本文介绍了请从系统注销事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我做的这是用来清除临时文件,历史记录等,当用户注销的应用程序。所以,我怎么能知道,如果系统要注销(在C#)?
I am doing an application which is used to clear the Temp files, history etc, when the user log off. So how can I know if the system is going to logoff (in C#)?
推荐答案
有一个在环保类属性的讲述,如果关机过程已经启动:
There is a property in Environment class that tells about if shutdown process has started:
Environment.HasShutDownStarted
但一些谷歌上搜索后,我发现,这可能是帮助你:
But after some googling I found out that this may be of help to you:
using Microsoft.Win32;
//during init of your application bind to this event
SystemEvents.SessionEnding +=
new SessionEndingEventHandler(SystemEvents_SessionEnding);
void SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e)
{
if (Environment.HasShutdownStarted)
{
//Tackle Shutdown
}
else
{
//Tackle log off
}
}
但是,如果你只希望清除临时文件,然后我想关机区分或注销的任何后果不给你。
But if you only want to clear temp file then I think distinguishing between shutdown or log off is not of any consequence to you.
这篇关于请从系统注销事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!