How to get caller's thread?

Is there any official way to get the caller's thread to determine if the current thread is different from the caller's thread

Thanks in advance!



Answer this question

How to get caller's thread?

  • Bubba76

    The callers thread will always be the same as the current thread. If a thread calls a function, the thread passes into a function. The only case where this is not true if when creating a new thread, and in that case, the only way would be to pass the creators thread ID to the new thread.

  • Amos Soma

    As Sean points out, the current thread will always be the same as the caller's thread. If you want to see if the caller's thread is different then another thread (like the main thread) you'll have to store a reference to that thread (via Thread.CurrentThread upon startup) then compare that to Thread.CurrentThread in the code that could be called by another thread.

  • JohnBurton

    You can use System.Threading.Thread.CurrentThread.ManagedThreadId to get an Id of the thread. You can then compare the thread ids to see if they are different.

    Mark.



  • How to get caller's thread?