Search code examples
c#multithreadingvisual-studio-2010visual-studio-debugging

Continue debugging in VS2010 while all threads are in sleep, wait or join


I have an app where there are several threads, and most of the time they are just waiting for an event to happen (eg with a AutoResetEvent.Wait).

In such a case if I try to use the immediate window to execute commands I get "Cannot evaluate expression because the current thread is in a sleep, wait, or join", no matter what thread I use. I'm wondering if there's any trick that can be used to eg make the thread stop waiting (like somehow set the AutoResetEvent).

I've read Debugging whilst paused and 'cannot evaluate expression' so I fear it's probably not possible.


Solution

  • I think your only options

    • to inject in advance some thread that will not ever be stopped in native code (busy wait of some sort). You'll effectively lose one core but at least will be able to debug.
    • have special thread that will wait for some external command to trigger events...
    • give up on expressions/immediate window and rely on memory dumps or using WinDbg with SoS.

    Basically without having managed thread that is not stuck in native code you can't safely run managed code in debugged process (nothing new in this area since linked 2010 question).