PInvoke threading issue

  • Thread starter Brett Robichaud
  • 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-
 
W

Willy Denoyette [MVP]

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.
 
B

Brett Robichaud

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-
 
K

Kevin Yu [MSFT]

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."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top