Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

dangerousThreadingAPI MDA

The dangerousThreadingAPI managed debugging assistant (MDA) is activated when the Thread.Suspend method is called on a thread other than the current thread.

An application is unresponsive or hangs indefinitely. System or application data might be left in an unpredictable state temporarily or even after an application has been shut down. Some operations are not completing as expected.

Symptoms can vary widely due to the randomness inherent to the problem.

A thread is asynchronously suspended by another thread using the Suspend method. There is no way to determine when it is safe to suspend another thread which might be in the middle of an operation. Suspending the thread can result in the corruption of data or the breaking of invariants. Should a thread be placed into a suspended state and never resumed using the Resume method, the application can hang indefinitely and possibly damage application data. These methods have been marked as obsolete.

If synchronization primitives are held by the target thread, they remain held during suspension. This can lead to deadlocks should another thread, for example the thread performing the Suspend, attempt to acquire a lock on the primitive. In this situation, the problem manifests itself as a deadlock.

Avoid designs that require the use of Suspend and Resume. For cooperation between threads, use synchronization primitives such as Monitor, ReaderWriterLock, Mutex, or the C# lockstatement. If you must use these methods, reduce the window of time and minimize the amount of code that executes while the thread is in a suspended state.

This MDA has no effect on the CLR. It only reports data about dangerous threading operations.

The MDA identifies the dangerous threading method that caused it to be activated.

<mdaConfig>
  <assistants>
    <dangerousThreadingAPI />
  </assistants>
</mdaConfig>

The following code example demonstrates a call to the Suspend method that causes the activation of the dangerousThreadingAPI.

using System.Threading;
void FireMda()
{
    Thread t = new Thread(delegate() { Thread.Sleep(1000); });
    t.Start();
    // The following line activates the MDA.
    t.Suspend(); 
    t.Resume();
    t.Join();
}
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.