Jump to content

Recommended Posts

Posted

Ever wondered how much time you spend waiting for Visual Studio to respond?

Well its been driving me nuts for a while so I wrote a little app to tracks the time that VS 2008 spends "not responding".

I think you'll be shocked by the results on solutions with 15+ projects.

 

Hopefully making this information available to others will motivate Microsoft to fix these problems.

 

Heres the code for your enjoyment (tested with VS 2008)..

 

using System;

using System.Diagnostics;

using System.Runtime.InteropServices;

using System.Threading;

 

namespace CalulateHangTime

{

[Flags]

public enum SendMessageTimeoutFlags : uint

{

SMTO_NORMAL = 0x0000,

SMTO_BLOCK = 0x0001,

SMTO_ABORTIFHUNG = 0x0002,

SMTO_NOTIMEOUTIFNOTHUNG = 0x0008

}

 

public static class ExternalMethods

{

[DllImport("user32.dll", SetLastError = true)]

public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

 

[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]

public static extern IntPtr SendMessageTimeout(IntPtr hWnd, uint Msg,

UIntPtr wParam, IntPtr lParam, SendMessageTimeoutFlags fuFlags,

uint uTimeout, out UIntPtr lpdwResult);

}

 

class Program

{

static readonly uint WAIT_MILLISECONDS = 2;

static readonly int SLEEP_MILLISECONDS = 1000;

 

static void Main(string[] args)

{

long seconds = 0;

Stopwatch stopWatch = new Stopwatch();

stopWatch.Start();

while (true)

{

IntPtr hWnd = ExternalMethods.FindWindow("wndclass_desked_gsk", null);

if (hWnd == IntPtr.Zero)

throw new InvalidOperationException("Handle to window could not be found");

 

 

UIntPtr result;

IntPtr success = ExternalMethods.SendMessageTimeout(hWnd, 0, UIntPtr.Zero, IntPtr.Zero,

SendMessageTimeoutFlags.SMTO_ABORTIFHUNG, WAIT_MILLISECONDS, out result);

 

if (success == IntPtr.Zero)

{

seconds += SLEEP_MILLISECONDS / 1000;

 

Console.WriteLine("Visual Studio is hung. {0}/{1} seconds wasted", seconds, stopWatch.Elapsed.TotalSeconds);

}

else

{

Console.WriteLine("Visual Studio is running fine.");

}

 

Thread.Sleep(SLEEP_MILLISECONDS);

}

}

}

}

 

 

 

More...

 

View All Our Microsoft Related Feeds

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...