在关闭/重新启动期间获得一个无形的C#程序关闭? [英] Getting a formless C# program to close itself during shutdown/restart?

查看:156
本文介绍了在关闭/重新启动期间获得一个无形的C#程序关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个程序,直到需要的时候才会创建任何表单。问题是,它阻止关机自动继续。我看过讨论关于如果添加一个,以形成关闭事件,以检查是否由于关闭,但正如我所说,我的程序意图没有任何形式直到需要。

I'm writing a program which creates no forms at all until one is required. The problem is, it's preventing shutdown from continuing automatically. I've seen discussions about adding an if to form closing events to check if it's due to shutdown, but as I've said, my program is meant to have no forms at all until required.

是否有任何事件或其他一些方法可以让我知道我的程序何时关闭自己以允许Windows自动关闭? 它不是多线程的

Is there any event or some other method that will allow me to know when my program should be closing itself to allow for Windows to shut itself down automatically? And it's not multithreaded.

推荐答案

您可以使用 SystemEvents 类,以听用户注销,或关闭。

You can use the SystemEvents class, to "listen to" users logging out, or shutting down.

如果我正确理解文档(与Reflector的深入研究证实了这一点):

If I understand the documentation correctly (and a deep study with Reflector confirms this):


  • 系统事件将产生一个从Windows接收消息的新线程(它有自己的消息传递器)。

  • 收到事件后,您的代码将被调用,从新线程。你应该知道这一点。

这篇关于在关闭/重新启动期间获得一个无形的C#程序关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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