Hi Brett,
It is strange, can you post the code the main UI thread doing after you
have created the working thread.
Did the main UI threading doing something to wait for the working thread?
Is there any race condition between the main UI thread and the working
thread which will do the P/Invoke?
Best regards,
Peter Huang
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
Brett Robichaud - 05 Oct 2004 18:35 GMT
No the main UI thread is not waiting on the worker thread in any way. I
actually experiemented with join and other techniques for waiting on the
thread and it acted exactly the same. This really brought me to the
conclusion that the worker thread is somehow blocking the main ui thread.
The code I'm calling in the worker thread is a code protection library by
Aladdin. They have a technique where they encrypt a DLL using a hardware
dongle (hasp). It is a very slow process to unencrypt it so I decided to
thread the pinvoke call. I have no idea what they are doing down there but
it definitely does not act like a good threaded citizen.
-Brett-
> Hi Brett,
>
[quoted text clipped - 11 lines]
> Get Secure! - www.microsoft.com/security
> This posting is provided "AS IS" with no warranties, and confers no rights.
"Peter Huang" - 06 Oct 2004 04:35 GMT
Hi Brett,
So far it is hard to guess what had happen, I think there must be something
underlying race condition which will cause the blcok.
I think you would better contact MS PSS which will do further touble
shooting about your issue. e..g live debugging or dump analysis which is
beyond newsgroup support boundary.
Thank you for you understanding!
Best regards,
Peter Huang
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
"Peter Huang" - 06 Oct 2004 09:56 GMT
Hi,
One possibility is that if the third-party dll called a COM object which is
main threaded that is to say we did not specified the thread model for the
COM Object. In this way, the COM object will be created and running on the
main thread, i.e. the main UI thread which may cause the main UI form
thread blocked. Usually the main thread is the first thread in the process.
So I think you may try to change your code as below.
<code snippet>
[STAThread]
static void Main()
{
//run the winform in the second thread.
Thread th = new Thread(new ThreadStart(ThreadProc));
th.Start();
//Run the P/Inovke code in the main thread, try to replace
the three code lines below
TestCOMP.COMPClass tcc = new TestCOMP.COMPClass();
tcc.SleepVB(1000);
}
public static void ThreadProc()
{
Application.Run(new Form1());
}
</code snippet>
Best regards,
Peter Huang
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.