PInvoke threading issue

  • Thread starter Thread starter Brett Robichaud
  • Start date Start date
B

Brett Robichaud

I have created a simple background thread to make one pinvoke call into a
DLL I've created. My Winforms app spawns the thread in the form load event
then go about it's business. The problem is that my form appears to be
blocked while the background thread is running.

I am very familir with threads in unmanaged code but am just getting into
them in C#. Are there issues I need to be aware of with regards to
threading a simple pinvoke call?

As an experiment I replaced my pinvoke call with a simple
Thread.Sleep(5000). This gave me the result I expected, my UI was
responsive during the entire 5 seconds the thread was waiting. Changing the
wait back into a pinvoke call caused my UI to not redraw until the pinvoke
call completed.

Any idea what's up?

-Brett-
 
What exactly are you doing in your PInvoke'd function? Looks like you are
blocking the message pump or preventing the message loop to call the MSG
handler because you are "monopolizing" the CPU.

Willy.
 
My code is wrapping a 3rd party library so I honestly don't know fully what
they are doing. So it is possible that something down in that unmanaged
code could cause the main ui thread to block? I guess I was just looking to
see if there were some fundamental issues with using pinvoke in a worker
thread that I needed to be aware of. Sounds like that isn't the case.

-Brett-
 
Hi Brett,

We have reviewed this issue and will reply to you in another thread in
microsoft.public.dotnet.framework.interop.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top