简体   繁体   中英

How do I make a console application appear “Not Responding”?

For testing, what is the easiest way to make a program appear "Not Responding" ? Interrupt Windows messages or put it in an infinite loop?

I have tried a simple loop like

while(true)

But that does not work. The test application is a C# console app. Does the fact that it's running in a console make it "more responsive"? Perhaps there are some parts of the added console handling that make it respond all the time?

Update:

Changed it to a simple Winform Application put that into an infinite loop. Worked lika a charm. Thanks to Servy.

A console application will never be "Not Responding" from the point of view of Windows Task Manager. In reality task manager isn't running your program, it's running a shell (cmd.exe) that is running your program, and that shell is written such that it will always be responding even if your program isn't. If you aren't running your program through a shell but are starting it directly, then there won't be any UI for the program and it won't be an "Application" in task manager (meaning it won't show up in the "Application" tab), it will just be a process.

If you just need to mimic any program "Not Responding" from the point of view of task manager you should make a simple winforms application and put that in an infinite loop. If there is some obscure way of making a program appear "Not Responding" from a console app, at the very least it will be much harder than from any of the standard desktop GUI types.

你可以做一个Thread.Sleep(X)

使程序“无响应”无限期的最简单方法是使用无限循环:

while(true);

Do any work on the UI thead (for a UI application)

Thread.Sleep  



  While (true)

this might give some insight into more of what your trying to accomplish ( .net console app stop responding when printing out lots of chars in a row )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM