Skip to content

Instantly share code, notes, and snippets.

@SimonCropp
Created October 14, 2014 03:11
Show Gist options
  • Select an option

  • Save SimonCropp/8a5cd61fe360da9dc66c to your computer and use it in GitHub Desktop.

Select an option

Save SimonCropp/8a5cd61fe360da9dc66c to your computer and use it in GitHub Desktop.
PerformanceMonitor.GetData
internal byte[] GetData(string item)
{
int num = 17;
int millisecondsTimeout = 0;
int error = 0;
new RegistryPermission(PermissionState.Unrestricted).Assert();
while (num > 0)
{
try
{
return (byte[]) this.perfDataKey.GetValue(item);
}
catch (IOException ex)
{
error = Marshal.GetHRForException((Exception) ex);
switch (error)
{
case 1722:
case 1726:
case 6:
this.Init();
goto case 170;
case 170:
case 258:
case 21:
case 167:
--num;
if (millisecondsTimeout == 0)
{
millisecondsTimeout = 10;
continue;
}
else
{
Thread.Sleep(millisecondsTimeout);
millisecondsTimeout *= 2;
continue;
}
default:
throw SharedUtils.CreateSafeWin32Exception(error);
}
}
catch (InvalidCastException ex)
{
throw new InvalidOperationException(SR.GetString("CounterDataCorrupt", new object[1]
{
(object) this.perfDataKey.ToString()
}), (Exception) ex);
}
}
throw SharedUtils.CreateSafeWin32Exception(error);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment