sychronizing asychronous calls to DllImport function

  • Thread starter Thread starter William Johnston
  • Start date Start date
W

William Johnston

Hello,

I need to perform synchronous calls to a DllImport function that is asychronous. (The Dllmport function returns immediately.)

So far I have a timer that waits inside a ThreadPool queue. But I would rather not use anything close to time-sharing.

Here is my code:
[
void mainloop ()
{

// call to asynchronous DllImport function
CreateVOBSegment(hwnd, strSourceVOBFilename, strBegTimeStamp, strEndTimeStamp, strDestFilename);

ThreadPool.QueueUserWorkItem(new WaitCallback(VOBExtractParser.Sleep), autoEvent);
autoEvent.WaitOne();
}
}
/// <summary>
/// thread that waits for 20 seconds
/// </summary>
private static void Sleep(object stateInfo) {
Thread.Sleep(TIMEOUT);
((AutoResetEvent)(stateInfo)).Set();
}

]

Do you have any suggestions?

Regards,
William Johnston
 
Hello,

I need to perform synchronous calls to a DllImport function that is asychronous. (The Dllmport function returns immediately.)

So far I have a timer that waits inside a ThreadPool queue. But I would rather not use anything close to time-sharing.

Here is my code:
[
void mainloop ()
{

// call to asynchronous DllImport function
CreateVOBSegment(hwnd, strSourceVOBFilename, strBegTimeStamp, strEndTimeStamp, strDestFilename);

ThreadPool.QueueUserWorkItem(new WaitCallback(VOBExtractParser.Sleep), autoEvent);
autoEvent.WaitOne();
}
}
/// <summary>
/// thread that waits for 20 seconds
/// </summary>
private static void Sleep(object stateInfo) {
Thread.Sleep(TIMEOUT);
((AutoResetEvent)(stateInfo)).Set();
}

]

How does the API for CreateVobSegment document that it has completed?
Does it post a message to hwnd's message loop (i am guessing since you
pass an HWND)? You could override the WndProc function in this case:
public class Form1 : Form
{
AutoResetEvent processComplete = new AutoResetEvent(false);
const int MESSAGE_CODE_PROCESS_COMPLETE = 0x401;

protected override void WndProc(ref Message m)
{
if (m.Msg == MESSAGE_CODE_PROCESS_COMPLETE)
{
processComplete.Set();
m.Result = IntPtr.Zero;
return;
}
base.WndProc(ref m);
}
}
 
Hello,

I need to perform synchronous calls to a DllImport function that is asychronous. (The Dllmport function returns immediately.)

So far I have a timer that waits inside a ThreadPool queue. But I would rather not use anything close to time-sharing.

Here is my code:
[
void mainloop ()
{

// call to asynchronous DllImport function
CreateVOBSegment(hwnd, strSourceVOBFilename, strBegTimeStamp, strEndTimeStamp, strDestFilename);

ThreadPool.QueueUserWorkItem(new WaitCallback(VOBExtractParser.Sleep), autoEvent);
autoEvent.WaitOne();
}
}
/// <summary>
/// thread that waits for 20 seconds
/// </summary>
private static void Sleep(object stateInfo) {
Thread.Sleep(TIMEOUT);
((AutoResetEvent)(stateInfo)).Set();
}

]

Do you have any suggestions?

Regards,
William Johnston

If CreateVOBSegment really is asynchronous thenit must report when it
completes somehow. How does it do that.

Also, there is no advantage to using the ThreadPool the way you are.
The behavior is the same as placing the Thread.Sleep call in the
mainloop method.
 
Wow! I didn't realize my use of ThreadPool.

I will ask the technical contact regarding the end of processing message.

Thanks.

William Johnston
 

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

Similar Threads


Back
Top