5

I don't know why, but many computers hangs on following operation:

void Init()
{
    net1 = new List<PerformanceCounter>();
    net2 = new List<PerformanceCounter>();
    foreach (string instance in new PerformanceCounterCategory("Network Interface").GetInstanceNames())
    {
        net1.Add(new PerformanceCounter("Network Interface", "Bytes Received/sec", instance));
        net2.Add(new PerformanceCounter("Network Interface", "Bytes Sent/sec", instance));
    }
}

//Once in 1 second
void UpdateStats()
{
    Status.Text = "";
    for (int i = 0; i < net1.Count; i++)                    
         Status.Text += string.Format("{0}/{1} Kb/sec;   ", net1[i].NextValue() / 1024, net2[i].NextValue() / 1024);
}

On some computes program hangs completely on first call of UpdateStats(), others experiencing 100% CPU load but program works (slowly). Other counters like new PerformanceCounter("Processor", "% Processor Time", "_Total") seems to work fine.

Any suggwstions why is that?

Poma
  • 8,174
  • 18
  • 82
  • 144
  • WTB Observer-Pattern based Performance Counters, gogo Rx – Aren May 19 '10 at 18:00
  • I think this could be a permission issue... –  May 19 '10 at 18:43
  • We have same issue here. It just hangs, maybe similar to this one: http://sharepoint.nailhead.net/2010/05/application-hangs-caused-by-calling.html So far the solution is to have another thread to detect if the counter thread hangs more than the expected time then just close it and instantiate another thread – unruledboy Mar 19 '13 at 01:08

1 Answers1

1

Removing printer references helped eliminate a hang on the initial

  new PerformanceCounter("Processor", "% Processor Time", "_Total").  

Now we get a fresh error message instead of hang so can trace it. From:

Answer about printer drivers

We had two similar dell laptops (one newer), both with Windows 8, MVSV 2013, and IIS Express 8. One would hang, one would not.

Community
  • 1
  • 1
crokusek
  • 5,345
  • 3
  • 43
  • 61