Going after VS, This time with numbers
I had enough of waiting for VS. I keep saying that it is slow and that it is hunging my system. So I decided to run a test. Tomorrow I am going to use this little program to know how much time I am wasting because of VS.
class Program
{
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
static void Main(string[] args)
{
DataTable table = new DataTable("waiting");
table.Columns.Add("elapsed", typeof(TimeSpan));
Process[] processes = Process.GetProcessesByName("devenv");
if (processes.Length == 0)
{
Console.WriteLine("Devenv is not running");
return;
}
Process devenv = processes[0];
IntPtr handle = devenv.MainWindowHandle;
while (devenv.HasExited == false)
{
DateTime start = DateTime.Now;
SendMessage(handle, 0, IntPtr.Zero, IntPtr.Zero);
TimeSpan end = DateTime.Now - start;
if (end.Milliseconds > 5)
{
DataRow row = table.NewRow();
row[0] = end;
table.Rows.Add(row);
table.WriteXml("log.xml");
}
Thread.Sleep(200);
}
}
}
Yes, I know it is ugly, and not safe, etc. It is throw away code and I wrote it in five minutes.
For the curious, this will ping VS ("devenv" is the process name) with a null windows message every 0.2 seconds (this is the length of time that it takes you to feel slugishness). Because the message it sends is syncronous, it is able to tell how long VS is spening not responding to messages (effectively hung).
Comments
Comment preview