如何编程以防止 Windows“无响应"对话 [英] How to program to prevent the Windows "Not Responding" dialog

查看:28
本文介绍了如何编程以防止 Windows“无响应"对话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当应用程序在 5 秒内无法响应时(

理想情况下,5 秒以上的执行不应阻塞主/事件处理线程,但是否有一种简单的(例如,MFC C++ 的 1 行)方式与 Windows 通信主线程正忙且不应阻塞被视为要关闭的无响应"应用程序?是简单地定期调用 peak PeekMessagePM_NOREMOVE?

解决方案

确实没有什么技巧可以解决这个问题.任何对消息泵的胡闹都可能导致各种灾难,尤其是在 COM 和其他系统消息处理方面.

不要阻塞主线程.

将运行时间较长的任务移至后台或工作线程,并轮询未来以完成或让线程将消息发送回 GUI 以表示它已完成,然后检索所需的结果.

When an application fails to be responsive for 5 seconds (source), Windows can display "(Not Responding)" in the title bar and in some cases show a "not responding" dialog:

Ideally, the 5+ second execution should not block the main/event-processing thread, but is there a simple (e.g. 1 liner for MFC C++) way to communicate to Windows that the main thread is busy and shouldn't be treated as a "Not Responding" application to be closed? Is the quickest hack to simply periodically call peak PeekMessage with PM_NOREMOVE?

解决方案

There really are no hacks to solve this. Any monkeying about with the message pump can lead to all manner of disaster, especially with COM and other system message processing.

Don't hold up the main thread.

Move the longer running tasks to a background or worker thread and either poll a future for completion or have the thread post a message back to the GUI to signal it is complete and then retrieve the result required.

这篇关于如何编程以防止 Windows“无响应"对话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆