I am working on a multi-threaded Windows C # application that often causes calls to the native dll. These are blocking calls that can sometimes last quite a while.
In some situations, I would like to cancel these blocking calls to some worker threads from the main thread. The native API that I use provides a function for this purpose:
HRESULT CancelBlockingCall(DWORD ThreadID)
Although the documentation for CancelBlockingCall () is not very clear, I believe that I need to pass ThreadID to an OS-level thread that blocks the call. Based on the return codes I get from CancelBlockingCall (), I realized that Thread.ManagedThreadID is not what I need. I found the following in msdn (see note) :
The ThreadId operating system does not have a fixed relationship with a managed thread, because an unmanaged host can control the relationship between managed and unmanaged threads. In particular, a complex host can use the CLR Hosting API to schedule many managed threads against the same operating system thread or to move a managed thread between different operating system threads.
Does this mean that for me there is no way to correctly call CancelBlockingCall () on a managed thread? Is it impossible to determine ThreadId in the OS level thread in which the managed thread is currently running?
Odrade Aug 14 '09 at 20:13 2009-08-14 20:13
source share