Can anyone suggest a better design approach?

V

vikky

Hi,

I have a forms application which hosts an unmanaged dll. This dll
exposes some simple c style functions which I just call using pinvoke.
But all native functions call WaitForMultiple\singleObject and wait
for a particular event to come. The problem is, this event can fire
only when messages on the windows message queue gets processed. Hence
if I call these blocking functions from native DLL directly from .NET
code they just block the application forever.
The solution I thought is to start a new thread and make this thread
call the dll method. I shall also create an event and pass its handle
into the thread created, so that this newly created thread can wait
for this event to happen. But then I would end up creating thread each
time for every native dll API call(every native DLL APi call does a
waitforsingle\multiple objects). This is not good..
Can anybody suggest a better design approach?

Regards,
Vishal.
 
P

Peter Ritchie [C# MVP]

You should never WaitForMultipleObjets or WaitForSingleObject on a GUI thread
(unless there's a very short timeout).

Creating another thread to perform the blocking (calling WaitFor...) is the
recommended approach.
 

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