C#, how to avoid recursion elegantly?
<p>I've got an event-function, where the code inside the function may trigger calling the same function again (because a message loop is used). How can I avoid this or better "detect" this most elegantly? When it comes to multiple thread synchronization one could write:</p>

<pre><code>public void Closing(object sender, EventArgs e)
{
    lock(m_Object)
    {

        &lt;Code, which can trigger Closing again&gt;

    }
}
</code></pre>

<p>But in my case it is the same thread that may call the same function and thus lock fails to work.</p>
