By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,375 Members | 1,111 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,375 IT Pros & Developers. It's quick & easy.

sychronizing asychronous calls to DllImport function

P: n/a

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

Sep 17 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Sep 17, 10:30 am, "William Johnston" <willi...@tenbase2.comwrote:
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.

Sep 17 '07 #2

P: n/a
"William Johnston" <wi******@tenbase2.comwrote:
>
Wow! I didn't realize my use of ThreadPool.

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

Thanks.

William Johnston

Sep 18 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.