Search code examples
c#visual-studiodebuggingvisual-studio-debugging

ContextSwitchDeadlock was detected


I am running something similar to the following code in debug mode:

for (int i = 0; i < 5000; i++)
{
   for (int j = 0; j < 10; j++)
   {
     DoSomething();
   }
}

From time to time I am getting "ContextSwitchDeadlock was detected" from VS 2010. It seems that performance degrades with less RAM available. I have 8GB and able to run the program in around 8 minutes (there are LOTS of DB hits after the loops are done, so 8 minutes is not the loop time), on 4GB machines the time is doubled! From what I red,The MDA is fired because my loop runs for longer than 60 seconds. Essentially, it is a warning that a code is completely blocking the application.

What can I do to avoid these situations and improve speed?

Thanks!


Solution

  • You can ignore that exception (I've run into this before myself for long running methods).

    1. Hold ctrl+alt+e
    2. Click Find
    3. Type ContextSwitchDeadlock and press Enter
    4. Uncheck Thrown in the table
    5. Close the Exceptions configuration window by pressing OK