C
Christian Kaiser
We have a component that has no window. Well, no window in managed code - it
uses a DLL which itself uses a window, and this is our problem!
When the garbage collector runs and removes our component (created
dynamically by, say, a button click, and then not referenced any more), the
GC runs in a different thread, which prohibits the DLL to destroy its
window, resulting in a GPF when the WndProc of that window is called - the
code is gone (DLL unloaded), but the window still there....
Clear to see (took us hours, to be honest, to understand what caused the
GPF, as WinDBG somehow uses 100% CPU load if used with .NET 2.0), which was
a PITA and a lot of guesswork.
Is there a way to get around that problem, so that we can call a routine
from Dispose() in the context of the original thread?
We tried creating a window ("m_myLabel = new Label()") in the component's
constructor, and use a delegate and "m_myLabel.Invoke(...)" this to get a
synchroneous invoke in the original thread. Problem is, the component has no
form to create the "Label" window with, thus invoke throws an exception
telling us that a non-existing window does not support Invoke. Right it is.
Questions:
a) How can a window be created without a parent form (invisible,
independent, just for this delegate), or
b) is there a better way to tell the GC to use the original "main" thread?
Christian
uses a DLL which itself uses a window, and this is our problem!
When the garbage collector runs and removes our component (created
dynamically by, say, a button click, and then not referenced any more), the
GC runs in a different thread, which prohibits the DLL to destroy its
window, resulting in a GPF when the WndProc of that window is called - the
code is gone (DLL unloaded), but the window still there....
Clear to see (took us hours, to be honest, to understand what caused the
GPF, as WinDBG somehow uses 100% CPU load if used with .NET 2.0), which was
a PITA and a lot of guesswork.
Is there a way to get around that problem, so that we can call a routine
from Dispose() in the context of the original thread?
We tried creating a window ("m_myLabel = new Label()") in the component's
constructor, and use a delegate and "m_myLabel.Invoke(...)" this to get a
synchroneous invoke in the original thread. Problem is, the component has no
form to create the "Label" window with, thus invoke throws an exception
telling us that a non-existing window does not support Invoke. Right it is.
Questions:
a) How can a window be created without a parent form (invisible,
independent, just for this delegate), or
b) is there a better way to tell the GC to use the original "main" thread?
Christian