Is there a way to make something happen only if it is called from a particular thread?
<p>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.</p>

<p>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.</p>
