// Thread routine for the poll loop. It handles calls coming in from the debug engine as well as polling for debug events. private void ThreadFunc() { bool fQuit = false; while (!fQuit) { if ((m_debuggedProcess != null) && (m_debuggedProcess.IsPumpingDebugEvents)) { m_debuggedProcess.WaitForAndDispatchDebugEvent(ResumeEventPumpFlags.ResumeWithExceptionHandled); } // If the other thread is dispatching a command, execute it now. bool fReceivedCommand = m_opSet.WaitOne(new TimeSpan(0, 0, 0, 0, 100), false); if (fReceivedCommand) { if (m_fSyncOp) { try { m_op(); } catch (Exception opException) { m_opException = opException; } } else { m_op(); } // This lock ensures the m_op operations and the manual reset events are accessed atomicly lock (this) { fQuit = (m_op == m_quitOperation); if (!fQuit) { m_op = null; } m_opSet.Reset(); m_opComplete.Set(); } } } }