Results 1 to 3 of 3

Thread: Multithreading API functions and .NET

  1. #1

    Multithreading API functions and .NET

    So I'm porting some classes from Win32 to .NET. One of these classes, based on TThread, calls SetThreadAffinityMask():

    DWORD_PTR WINAPI SetThreadAffinityMask(
    __in HANDLE hThread,
    __in DWORD_PTR dwThreadAffinityMask
    );

    http://msdn2.microsoft.com/en-us/library/ms686247.aspx

    I haven't had problems calling other API functions, but with this one I can't find the parameter needed. When I try to pass the handle of the Thread, this handle doesn't fit because it is of "Thread" type, not "Integer". I tried using IntPtr, but it doesn't seem capable to convert the handle. Is there a way to obtain the API handle of the thread? Just thought maybe I should call another API function to get the current thread handle, but if you have any idea please let me know.

    Thanks!

  2. #2

    Multithreading API functions and .NET

    I am not sure how you are creating the thread (or where from)... but if you are using this method (CreateThread) from the main thread lets assume

    http://msdn2.microsoft.com/en-us/library/aa374779.aspx

    then you should retain the thread handle and pass it straight into SetThreadAffinityMask...

    However, if the code that calls SetThreadAffinityMask is on the same thread that you are setting the affinity of, you could get the handle by using (GetCurrentThread)
    http://msdn2.microsoft.com/en-us/library/ms683182.aspx

    Not really sure if that answers your question or even helps... just a thought...

  3. #3

    Multithreading API functions and .NET

    That's what I supposed, I'll try it at home. Thanks!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •