using System; using System.Collections.Generic; using System.Diagnostics; using System.Threading; using com.itac.mes.tools; namespace com.itac.mes.tools { public class StatisticWorker { private DateTime startupTime = DateTime.Now; private long count = 0; // Volatile is used as hint to the compiler that this data // member will be accessed by multiple threads. private volatile bool _shouldStop; private List versionList; public StatisticWorker() { Thread.CurrentThread.Name = "StatisticThread"; } // This method will be called when the thread is started. public void DoWork() { while (!_shouldStop) { Process process = Process.GetCurrentProcess(); ProcessThreadCollection threads = process.Threads; TimeSpan upTime = DateTime.Now - startupTime; string appName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name; String message = String.Format("{0} Statistics\n", appName) + String.Format(" {0,-21}: {1}\n", "Application started", startupTime.ToLocalTime()) + String.Format(" {0,-21}: {1}\n", "Uptime", upTime) + String.Format(" {0,-21}: {1}\n", "MachineName", process.MachineName) + String.Format(" {0,-21}: {1}\n", "MainModule", process.MainModule) + String.Format(" {0,-21}: {1,9:####0\\.###} Mb\n", "PrivateMemorySize64", process.PrivateMemorySize64 / 1024) + String.Format(" {0,-21}: {1,9:####0\\.###} Mb\n", "PeakWorkingSet64", process.PeakWorkingSet64 / 1024) + String.Format(" {0,-21}: {1,9:####0\\.###} Mb\n", "WorkingSet64", process.WorkingSet64 / 1024) + String.Format(" {0,-21}: {1,9:####0\\.###} Mb\n", "MinWorkingSet", process.MinWorkingSet.ToInt64() / 1024) + String.Format(" {0,-21}: {1,9:####0\\.###} Mb\n", "MaxWorkingSet", process.MaxWorkingSet.ToInt64() / 1024) + String.Format(" {0,-21}: {1}\n", "TotalProcessorTime", process.TotalProcessorTime) + String.Format(" {0,-21}: {1}\n", "UserProcessorTime", process.UserProcessorTime) + String.Format(" {0,-21}: {1}\n", "Threads", threads.Count); // jedes 10. Mal weitere Infos ausgeben if ((count % 10) == 0) { if (versionList != null) { foreach (KeyValue va in versionList) { message += String.Format(" {0,-21}: {1}\n", va.key, va.value); } } } LogHandler.log(Constants.LOGGER, TraceEventType.Information, message); // 1 Minute schlafen Thread.Sleep(60000); count++; } } public void RequestStop() { _shouldStop = true; } public void setVersionList(List versionList) { this.versionList = versionList; } } }