views:

266

answers:

3

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
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
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
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