Using PerformanceCounter to track memory and CPU usage per process?

For per process data: Process p = /*get the desired process here*/; PerformanceCounter ramCounter = new PerformanceCounter(“Process”, “Working Set”, p.ProcessName); PerformanceCounter cpuCounter = new PerformanceCounter(“Process”, “% Processor Time”, p.ProcessName); while (true) { Thread.Sleep(500); double ram = ramCounter.NextValue(); double cpu = cpuCounter.NextValue(); Console.WriteLine(“RAM: “+(ram/1024/1024)+” MB; CPU: “+(cpu)+” %”); } Performance counter also has other counters than … Read more

How to get the output of a System.Diagnostics.Process?

What you need to do is capture the Standard Output stream: p.StartInfo.RedirectStandardOutput = true; p.StartInfo.UseShellExecute = false; // instead of p.WaitForExit(), do string q = “”; while ( ! p.HasExited ) { q += p.StandardOutput.ReadToEnd(); } You may also need to do something similar with StandardError. You can then do what you wish with q. … Read more

When should I use Tracing vs Logger.NET, Enterprise Library, log4net or Ukadc.Diagnostics?

There are many similar questions here on SO: Logging best practices log4net versus TraceSource Silverlight Logging framework and/or best practices log4net vs. Nlog What’s the point of a logging facade? C# Logging. What should I use? You missed several commonly used logging frameworks. Here is a list of commonly used frameworks, some of which you … Read more

Difference between ElapsedTicks, ElapsedMilliseconds, Elapsed.Milliseconds and Elapsed.TotalMilliseconds? (C#)

Elapsed.TotalMilliseconds (double) returns the total number of whole and fractional milliseconds elapsed since inception e.g. a stopwatch stopped at 1.23456 seconds would return 1234.56 in this property. See TimeSpan.TotalMilliseconds on MSDN Elapsed.Milliseconds (int) returns the number of whole milliseconds in the current second e.g. a stopwatch at 1.234 seconds would return 234 in this property. … Read more