关闭时显示消息框. [英] Showing Message Box while Shutting Down .
本文介绍了关闭时显示消息框.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我单击关闭选项时,我想显示一个带有是/否"选项的消息框.应该在Windows Service的帮助下显示.
您能否为上述问题提供帮助,直接指导或提供源代码?
While I click on the turn off option, I would like show a message box with Yes/No Option. It should be shown with the help of Windows Service.
Could u pls, direct or give source code for the above problem?
推荐答案
您可以执行此操作-
在关闭之前,在代码中检查 消息框 结果
You could do this-
in your coding before shutting down check the messagebox result
DialogResult result = MessageBox.Show("Do you really want to shut down?",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Question,MessageBoxDefaultButton.Button2);
if (result == DialogResult.Yes)
{
// Code for shutdown
}
Windows服务本身不支持任何UI.
最好的办法是捕获停止事件 [ ^ ],然后启动将显示消息框的exe.
但是,如果机器已经关闭,则无论如何操作系统将关闭该消息框.
更好的方法是按照此处所述,自行处理WM_QUERYENDSESSION
或WM_ENDSESSION
[ ^ ].您可以
Windows service in itself does not support any UI.
The best you can do is catch the stop event[^] of the service and then launch an exe that will display a message box.
However if the machine is already shutting down, the message box will be closed by the operating system anyway.
A better approach would be to handleWM_QUERYENDSESSION
orWM_ENDSESSION
on your own as described here[^]. You can do
这篇关于关闭时显示消息框.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文