Unmanaged thread in C#
-
I'm using a DLL written in C++ which creates a processing thread which processes items added to a queue from other threads. This works well from unmanaged code but I am now trying to use the DLL in a managed application. The thread is created and runs as expected processing items passed to it from C#, the problem occurs when I try to call Application.Run(dialog) or dialog.ShowDialog(). The form is destroyed immediately so it simply flashes on the screen and disappears. This does not happen when the unmanaged thread is not running. The loop within the C++ thread is simply:
while( true )
{
WaitForSingleObject(hEvent);
while( !queue.empty() )
{
DoProcess(queue.front());
}
}And the thread is created with:
g_hThread = CreateThread(NULL, NULL, ThumbnailThreadProc, NULL, 0, &g_nThreadId);
Is there a reason for this behaviour?
-
I'm using a DLL written in C++ which creates a processing thread which processes items added to a queue from other threads. This works well from unmanaged code but I am now trying to use the DLL in a managed application. The thread is created and runs as expected processing items passed to it from C#, the problem occurs when I try to call Application.Run(dialog) or dialog.ShowDialog(). The form is destroyed immediately so it simply flashes on the screen and disappears. This does not happen when the unmanaged thread is not running. The loop within the C++ thread is simply:
while( true )
{
WaitForSingleObject(hEvent);
while( !queue.empty() )
{
DoProcess(queue.front());
}
}And the thread is created with:
g_hThread = CreateThread(NULL, NULL, ThumbnailThreadProc, NULL, 0, &g_nThreadId);
Is there a reason for this behaviour?