I have an application that interacts with another application using SendMessage (among other things). Everything works fine until the other application hangs (either because it has actually frozen or it is doing a long, blocking call). I would like to simulate an application hanging using a C# WinForms application. Is there any way to start a long running, blocking call? Or maybe a way to cause the application to actually freeze? Maybe something like WebClient.DownloadString(), but something that will never return.
+5
A:
while(true) { } // busy waiting
Thread.Sleep(time); // blocking
Mehrdad Afshari
2009-05-04 17:23:15
Doh, so simple. I completely overlooked the obvious. I ended up going with this because it's infinite: System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
Jon Tackabury
2009-05-04 17:26:18
A:
If you want to simulate a long running task, use
Thread.Sleep(timeout);
and with Timeout.Infinite
if you want to block forever.
If you want to simulate heavy processor usage, too, use an infinite loop.
while (true) { }
Daniel Brückner
2009-05-04 17:24:06
A:
How about you just turn the message pump off? Then not only will your app appear to be frozen.. the system will actually report it as frozen (a la IsHungAppWindow(hWnd)).
Boo
2009-05-04 17:34:06