I am developing a .NET 2.0 plug-in based application. My application detects/loads plug-ins at run-time via a System.Reflection inspection of other .NET assemblies in a specified directory. This works great. My application contains a PropertyGrid control populated from [Browsable(true)] properties present in the loaded plug-ins. In this PropertyGrid, browsable-true-properties exhibit the following behavior:
- Properties of basic/primitive types (bool, string, etc.) load and cleanup properly
- Properties of user-defined types (like a plug-in side defined enum) load properly and cleanup properly when the user does not modify then at run-time.
- If a user modifies a non-standard type at run-time (i.e. changes the value of an enum via the PropertyGrid) the application hangs upon closing. This is my problem.
Using Visual Studio .NET 2005 and Red Gate's Reflector, I was able to isolate the hang to the following segment of code from Microsoft.Win32.SystemEvents.WindowThreadProc (I was working from the raw assembly, but I am 99% sure this is the right place):
while (flag)
{
if (UnsafeNativeMethods.MsgWaitForMultipleObjectsEx(0, IntPtr.Zero, 100, 0xff, 4) != 0x102)
{
goto Label_0072;
}
Thread.Sleep(1);
continue;
Label_0053:
if (msg.message == 0x12)
{
flag = false;
continue;
}
UnsafeNativeMethods.TranslateMessage(ref msg);
UnsafeNativeMethods.DispatchMessage(ref msg);
Label_0072:
if (UnsafeNativeMethods.PeekMessage(ref msg, NativeMethods.NullHandleRef, 0, 0, 1))
{
goto Label_0053;
}
}
It appears 'flag' is not being set to true, hence my program sits in this loop forever. I found someone with a similar problem at .NET 247, but his recommended workaround:
System.Threading.Thread.CurrentThread.SetApartmentState(Threading.ApartmentState.STA)
didn't seem to fix things.
Any thoughts?
Thanks in advance.