我想知道Windows 7何时检测到我的程序占用了太多内存。所以我想处理这件事。如何订阅此事件(在应用程序关闭之前)。
Windows日志中的一些信息:
Windows成功地诊断出一种低虚拟内存状况。以下程序消耗了最多的虚拟内存。事件ID: 2004关键词:与耗尽系统提交限制有关的事件(虚拟内存)。
在Windows中检测低虚拟内存条件
发布于 2013-09-17 18:27:15
System.Diagnostics.EventLog eventLog = new System.Diagnostics.EventLog("System", ".", "Resource-Exhaustion-Detector");
eventLog.EnableRaisingEvents = true;
eventLog.EntryWritten += eventLog_EntryWritten;
static void eventLog_EntryWritten(object sender, System.Diagnostics.EntryWrittenEventArgs e)
{
if (e.Entry.Message.Contains(Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName)))
{
Logger.Error("Our application consumed too much memory `{0}`. So we stopping work right now to prevent reboot OS.", new object[] {e.Entry.Message},MethodBase.GetCurrentMethod());
GC.Collect();
//do smth
}
}https://stackoverflow.com/questions/18856424
复制相似问题