I have my own solution, which requires a one-time recompilation. I am sure that it can be translated into C # if necessary.
Define this structure:
struct THREAD_DATA { int ms; DWORD id; THREAD_DATA(DWORD _id, int _ms) : id(_id), ms(_ms) {}; };
and these two functions:
DWORD WINAPI PauseThread(LPVOID p) { THREAD_DATA* ptd = (THREAD_DATA*)p; HANDLE target = OpenThread(THREAD_SUSPEND_RESUME, FALSE, ptd->id); SuspendThread(target); Sleep(ptd->ms); ResumeThread(target); delete p; return 0; } void PauseCurrentThread(int ms) { THREAD_DATA* ptd = new THREAD_DATA(GetCurrentThreadId(), ms); HANDLE h = CreateThread(NULL, 0, &PauseThread, (LPVOID)ptd, 0, 0); }
When you are at a breakpoint, use the Immediate window to launch: PauseCurrentThread(5000) or regardless of your delay in milliseconds.
If you want to do this in several projects without tools, I could probably develop a Visual Studio extension to do this automatically.
source share