我正在做一个应用程序,用于在用户注销时清除临时文件、历史记录等。那么我如何知道系统是否要注销(在 C# 中)?
最佳答案
Environment 类中有一个属性告诉我们关闭过程是否已经开始:
Environment.HasShutDownStarted
但经过一些谷歌搜索后,我发现这可能对你有帮助:
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
}
}
但如果您只想清除临时文件,那么我认为区分关机或注销对您来说没有任何影响。
关于c# - 从系统中获取注销事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/984881/