Jon Tackabury
Jon Tackabury

Reputation: 49247

Simulating a locked/hung application

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.

Upvotes: 2

Views: 2829

Answers (3)

Sam Axe
Sam Axe

Reputation: 33738

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

Upvotes: 0

Daniel Brückner
Daniel Brückner

Reputation: 59645

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) { }

Upvotes: 0

Mehrdad Afshari
Mehrdad Afshari

Reputation: 421988

while(true) { } // busy waiting
Thread.Sleep(time); // blocking

Upvotes: 5

Related Questions