I have a method that for thread-safety reasons should only ever be used by a particular thread. If another thread tries to use it, I would like an exception to be thrown.
public void UnsafeMethod()
{
if (CurrentThreadId != this.initialThreadId)
throw new SomeException("Can only be run on the special thread.");
// continue ...
}
How can I find the CurrentThreadId
in the code above? Or alternatively is there some other way of achieving what I want to do?