Okay, this is a pretty weird question, but the situation is this. I’ve got a communication library I’ve been working on, and one of its many features is a background thread that accepts all incoming packets from a socket and doles them out as needed. In the simplest form, you can have either a request or a response to a request. Multiple threads can send on the same socket using this library by sending a request, and then waiting for a signal (event) from the background thread when its response has arrived.
You define a delegate associated with the background thread to handle what happens with incoming requests. The short of it is, you can try to send a request from this delegate. Since this is all on the same thread as the background receiving thread, it becomes deadlocked (the thread will block, waiting for its response, which will never happen). These are situations I and most people know to avoid, but I would love to have a way to throw an exception, or maybe have a compile time check that prevents the programmer from trying to call a certain method, the one which sends a request, from the thread that handles receiving.
You can name Your thread
Or you can create a static field to hold Your thread Id
And then in Your method