编程时发现ASP.NET辅助进程和应用程序域上次启动? [英] Programmatically find when the ASP.NET worker process and app domain last started?
问题描述
在ASP.NET:
-
我如何知道当ASP.NET辅助进程上次重新启动?
-
在ASP.NET中,我怎么能告诉当应用程序域回收的最后
有关工作进程,可以通过编程读过程 - >执行时间从相应的PERF。计数器(1),或直接从的System.Diagnostics.Process 命名空间;为的AppDomain ,你可以设置在启动一个应用程序级的变量作为基线和衡量的手动操作。
斯科特·米切尔居然有一对夫妇这一点,仍然是相关8年后好职位,不管你信不信(2)。运行在卡西尼(Vista中,VS 2008),我看到一个精确的系统正常运行时间:
TimeSpan.FromMilliseconds(Environment.TickCount)
...和准确的过程/ AppDomain中了次与这些:
的foreach(在Process.GetProcessesByName进程p(WebDev.WebServer))
{
的Response.Write(DateTime.Now.Subtract(p.StartTime)的ToString()+< BR />中);
}的Response.Write(DateTime.Now.Subtract((DateTime的)应用程序[开始时间])的ToString());
我也能获得正确的 PerfomanceCounter ,但似乎无法读取正确的值(始终为零,我的设置下):
的Response.Write(新的PerformanceCounter(过程,经过时间,WebDev.WebServer)NextValue()+< BR />中。);
斯科特的文章是绝对值得一读 - 有丰富的信息在 ProcessInfo 和 ProcessModelInfo (如 ProcessModelInfo.GetHistory ),但遗憾的是它不提供卡西尼号:
Process指标仅可用
当ASP.NET进程模型
启用。当在版本上运行
在工作进程IIS 6或更高版本
隔离模式,这个功能是不是
支持。
块引用>心连心
(1)<一href=\"http://serverfault.com/questions/90927/lifetime-of-iis-worker-process-or-appdomai\">http://serverfault.com/questions/90927/lifetime-of-iis-worker-process-or-appdomai
(2) http://www.4guysfromrolla.com/articles/041002-1的.aspx
In ASP.NET:
How can I tell when the ASP.NET worker process last restarted?
In ASP.NET, how can I tell when the app domain last recycled?
解决方案For the worker process, you can programmatically read Process -> Elapsed Time from the corresponding perf. counter (1) or directly from the System.Diagnostics.Process namespace; for the AppDomain, you can set an application-level variable at start-up to serve as your baseline and measure against that manually.
Scott Mitchell actually has a couple of good posts on this that are still relevant 8 years later, believe it or not (2). Running on Cassini (Vista, VS 2008), I'm seeing an accurate system up-time with:
TimeSpan.FromMilliseconds(Environment.TickCount)
...and accurate Process/AppDomain up-times with these:
foreach (Process p in Process.GetProcessesByName("WebDev.WebServer")) { Response.Write(DateTime.Now.Subtract(p.StartTime).ToString() + "<br/>"); } Response.Write(DateTime.Now.Subtract((DateTime)Application["StartTime"]).ToString());
I'm also able to obtain the correct PerfomanceCounter, but can't seem to read the correct value (always zero, under my setup):
Response.Write(new PerformanceCounter("Process", "Elapsed Time", "WebDev.WebServer").NextValue() + "<br/>");
Scott's articles are definitely worth a read - there's a wealth of info in ProcessInfo and ProcessModelInfo (eg. ProcessModelInfo.GetHistory), but unfortunately it's not available on Cassini:
Process metrics are available only when the ASP.NET process model is enabled. When running on versions of IIS 6 or newer in worker process isolation mode, this feature is not supported.
UPDATE: great explanation of how to read the counter correctly to avoid the zero on NextValue(): http://blogs.msdn.com/b/bclteam/archive/2006/06/02/618156.aspx
HTH
(1) http://serverfault.com/questions/90927/lifetime-of-iis-worker-process-or-appdomai
(2) http://www.4guysfromrolla.com/articles/041002-1.aspx
这篇关于编程时发现ASP.NET辅助进程和应用程序域上次启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!