c# - Why this winform does not show up after Hide is called on its second iteration? -
my current situation follow:
- application injects library application b
- application uses getprocessaddress , getmodule call onstart method in library
within onstart/onstop method initiate/hide winform, in context this:
private static pluginmanager _pluginmanager; public static void onstart() { // log file code here if (_pluginmanager == null) { _pluginmanager = new pluginmanager(); } // log file code here _pluginmanager.show(); // log file code here } public static void onstop() { if (_pluginmanager != null) { // log file code here _pluginmanager.hide(); // log file code here } }
the pluginmanager
winform close event override call hide()
technically(i assume) winform never disposed/closed?
- once application done tasks , close, uses getprocessaddress , getmodule call onstop method of library
everything works expected far winform shows @ onstart , hides on onstop expected.
now when start application again , calls onstart method, winform never shows up, don't error messages nor simple doesn't open.
i know function called because outputs log file line before , line after calls show()
.
- as title says, why winform doesn't show in second iteration?
- what else can find issue?
on further tests found out if dispose of winform , reinitialize it, winform work every call:
public static void onstart() { // log file code here if (_pluginmanager == null) { _pluginmanager = new pluginmanager(); } else { _pluginmanager.dispose(); _pluginmanager = new pluginmanager(); } // log file code here _pluginmanager.show(); // log file code here }
however still unaware of why required given winform never disposed of initial code.
my case off-topic? can't provide reproducible code of issue , unhappily above collect, 1 able point me in right direction or at.
this threading problem. should call .show() [stathread] , should call .hide() same thread called .show(). this:
private static isynchronizeinvoke _invoker = null; public static void onstart() { _invoker.invoke((action)(() => { // log file code here if (_pluginmanager == null) { _pluginmanager = new pluginmanager(); } // log file code here _pluginmanager.show(); // log file code here }), null); } public static void onstop() { if (_pluginmanager != null) { // log file code here _pluginmanager.invoke((action)(() => _pluginmanager.hide())); // log file code here } }
i don't know how application's main structured, can fill in _invoker open form.
[stathread] static void main() { application.enablevisualstyles(); application.setcompatibletextrenderingdefault(false); // application.run(new form1()); <-- usual startup // instead, grab object invoke on form1 form1 = new form1(); _invoker = form1; application.run(form1); }
you create wholly separate stathread , call application.run(_pluginmanager) instead of pluginmanager.show().
Comments
Post a Comment