本文介绍了关闭desk.cpl后,/p预览模式下的屏幕保护程序继续运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文:

我正在 Windows 8.1 上使用 VS2010 .NET 4.0 用 C# 开发屏幕保护程序.它非常忙",在初始加载时访问数据库并在显示给多显示器之前进行一些图像处理.

I'm developing a screensaver in C# with VS2010 .NET 4.0 on Windows 8.1. It's quite "busy", accessing a database on initial load and doing some image processing before displaying to multi-monitors.

问题:

在大多数情况下,a) 在/s 模式下鼠标/键盘移动或在/p 模式下关闭desk.cpl 时,进程会完全关闭.当我在/p 模式下运行(desk.cpl 打开)然后我启动设置"(/c 模式)或预览"(/s 模式)时,会出现问题.一旦这些新进程关闭,/p 模式就会如您所愿返回,但是当desk.cpl 关闭时/p 模式进程继续运行.这是间歇性的 - 有时它会关闭,有时它不会't.

In most cases the process shuts down cleanly either a) on mouse/keyboard movement in /s mode or when desk.cpl is closed in /p mode. A problem arises thought when I run in /p mode (desk.cpl open) and then I instigate either "settings" (/c mode) or "Preview" (/s mode). Once these new processes are closed the /p mode returns as you would expect but when desk.cpl is closed the /p mode process continues to run. This is intermittent however - sometimes it closes, sometimes it doesn't.

在/p 模式下,我明确关闭鼠标移动等时的表单,因为这不适用于desk.cpl 预览窗口.因此,我的假设是,desk.cpl 会终止我的进程,但这似乎并没有持续发生.

In /p mode I explicitly don't close the form on mouse movement etc as this is not appropriate for the desk.cpl preview window. My assumption therefore is that desk.cpl would kill my process but this doesn't seem to be happening consistently.

问题:

如何确保/p 模式始终关闭?

How can I ensure that /p mode will close down consistently?

推荐答案

两种方法.您可以监视 WM_DESTROY 的消息泵并关闭它,或者您可以设置计时器和监视器以查看是否还有可见窗口.请注意,当控制面板替换您时(自行关闭,或用户选择新的屏幕保护程序),您的窗口将被隐藏,我相信它已被破坏.既然您是屏幕保护程序,那么提早放弃似乎比永远坚持下去的风险要小.

Two methods. You can either monitor the message pump for WM_DESTROY and close down on that, or you can set a timer and monitor to see if you have a visible window any more. Note that when the control panel replaces you (closes itself, or user chooses a new screen saver), your window is hidden, and I believe destroyed. Since you are Screen Saver, it seems less risky to possibly abort early than to hang on forever.

所以设置一个非表单计时器(如果您的窗口被销毁,表单计时器可能会被销毁),并定期检查自己.正如有人在对您的问题的评论中指出的那样,您还可以监视 GetParent,以查看它是否发生变化.

So set a non-Form Timer (Form timers may get destroyed if your window is being destroyed), and check yourself periodically. You can also, as somebody points out in the comments to your question, monitor GetParent, to see if it changes.

这篇关于关闭desk.cpl后,/p预览模式下的屏幕保护程序继续运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 21:54