当PC重新启动时,C#.Net exe不会关闭,从而不让机器重新启动 [英] C# .Net exe doesn't close when PC is restarted, keeping the machine from restarting

查看:168
本文介绍了当PC重新启动时,C#.Net exe不会关闭,从而不让机器重新启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个内置C#的SmartClient,当它正在运行的PC被重新启动时,它们固定地保持打开状态。这将停止重新启动过程,除非用户首先关闭SmartClient或有其他手动干预。

We have a SmartClient built in C# that stubornly remains open when the PC its running on is being restarted. This halts the restart process unless the user first closes the SmartClient or there is some other manual intervention.

当基础架构团队远程安装需要一个机器重新启动。

This is causing problems when the infrastructure team remotely installs new software that requires a machine reboot.

有什么想法可以让SmartClient应用程序从Windows中识别关机/重启事件,并优雅地杀死自己?

Any ideas for getting the SmartClient app to recognize the shutdown/restart event from Windows and gracefully kill itself?

更新:
这是一个具有多个gui线程的高度线程化的应用程序。是的,多个gui线程。它真的是许多项目的整合,它们本身可以是独立的应用程序,所有这些项目都是从一个单一的exe启动和管理的,它们集中了这些管理方法并跟踪这些线程。我不相信使用后台线程是一个选项。

UPDATE: This is a highly threaded application with multiple gui threads. yes, multiple gui threads. Its really a consolidation of many project that in and of themselves could be standalone applications - all of which are launched and managed from a single exe that centralizes those management methods and keeps track of those threads. I don't believe using background threads is an option.

推荐答案

如果您有权访问该应用,则可以处理SessionEnded事件。

OK, if you have access to the app, you can handle the SessionEnded event.

...
Microsoft.Win32.SystemEvents.SessionEnded +=new
  Microsoft.Win32.SessionEndedEventHandler(shutdownHandler);

...

private void shutdownHandler(object sender, Microsoft.Win32.SessionEndedEventArgs e) {
  // Do stuff
}

这篇关于当PC重新启动时,C#.Net exe不会关闭,从而不让机器重新启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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