Reputation: 941
Suppose I have a reference to a Thread object, such as:
System.Threading.Thread thread;
If I want to determine whether the current thread is represented by this object, should the following code be used?
bool currentThread = (thread.ManagedThreadId == Thread.CurrentThread.ManagedThreadId);
I'm pretty sure this will work fine, but it seems strange that there wouldn't be a more direct method for checking this. Is there one?
Upvotes: 3
Views: 1161
Reputation: 46183
Just use Thread.CurrentThread
:
bool currentThread = (thread == Thread.CurrentThread);
Upvotes: 9