Note that there are some explanatory texts on larger screens.

plurals
  1. PODeadlock at rasing events in .net
    primarykey
    data
    text
    <p>I have a weird deadlock situation. After attached visual studio. I saw 3 threads that stuck.</p> <ol> <li><p>Thread 1:</p> <pre><code>if (SomeEvent != null) SomeEvent(this, new SomeArg) --&gt; Stuck </code></pre></li> <li><p>Thread 2:</p> <pre><code>if (SomeEvent2 != null) SomeEvent2(this, new SomeArg2) --&gt; Stuck </code></pre></li> <li><p>Main Thread:</p> <pre><code>public object (Delegate method, object[] args) { ... SynchronizationContext.Send(delegate(object state)) { ... method.DynamicInvoke(args); --&gt; Stuck } } </code></pre></li> </ol> <p>These three threads are stuck, and when I check their call stacks, I wasn't able to find any shared resource, like <code>lock()</code>, or <code>Monitor.Wait()</code>. I believe they all stuck on external calls.</p> <p>In addition, I can't tell what <code>method.DynamicInvoke(args)</code> is doing and what this method supposed to be.</p> <p>The only one thing I found is that the attached event handlers may cause deadlock. However, since VS has show me this is where it stucks, and not at the event handler code. I think it may be something else.</p> <p>In term of the application, I know this is a race condition, because the application was trying to perform loading and unload data around the same time, so this problem is rather hard to reproduce.</p> <p>My question are:</p> <ol> <li>Why would .NET thread hangs when raising an event, is it even possible?</li> <li>Does the Main UI thread need to be used when raising an event?</li> <li>If indeed it is possible for the event raising to deadlock, how should I prevent this?</li> </ol> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload