ContextSwitchDeadlock while debugging

This occurs while debugging a C# VSTO Word application:

ContextSwitchDeadlock was detected
Message: The CLR has been unable to transition from COM context 0x16a300 to COM context 0x16a020 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.

Has anyone else run into this and know of a way to get the CLR to ignore it.  After all, the debugger has control so, of course, there's a context switch deadlock.  D'oh!

Cheers, TC



Answer this question

ContextSwitchDeadlock while debugging

  • Kalpesh Vora

  • Moiz Mala

    Thanks Rupesh! That did the trick.

    Cheer, TC


  • Reiner7

    Well, it seems that I spoke too soon. I've not got rid of the annoying message, but this only masks the underlying problem. Apparently, the debugger loses contact with the Word application and even though I no longer receive the MDA exception, if I time out, I still lose the ability to debug the application. My only option at that point is to Detach and try to trap the error I'm looking for a bit further on in the data path. This is remarkably annoying. Any help that would get me past this problem would be greatly appreciated. :-)

    Cheers, TC


  • Lytse Sippe

  • JoeGeeky

    I've read the blog and I'd like to say that it isn't 'very rare' for me it's a major pain, occurring every few lines I step through (presumably because it's a multi-threaded app). I have disabled the MDA as suggested above, and now I don't get the error but I can still not step through code as I lose the call stack, and get the message 'No symbols are loaded for any call stack frame. The source code cannot be displayed.'.

    If anyone can help, I'd be eternally grateful. Thanks.

    Lesley


  • Bailey

    Hi Tony,

    What you are seeing is one of "Managed Debugging Assistants" (MDA) and can be disabled by Debug->Exceptions ... > Expand the MDA node and uncheck the box against contextswitchdeadlock .

    Hope that solves your problem.

    Thanks,

    Rupesh


  • PatAzzarello

    I too have to disagree.  This is not only common, but easily repeatable when debugging VSTO applications.  Moreover, disabling the MDA didn't solve my problem.  All it did was mask the problem.  So, I'm still at square one, the only difference is the absence of an irritating dialog box.

    <grumble/>

    Cheers, TC


  • ContextSwitchDeadlock while debugging