Hi,<br/><br/>Im having a problem and i dont know how to sort it out. Im pretty much a beginner really with C#.<br/><br/>Im trying to create an application that will tell the % Processor Time of each thread related to SQL Server - the only problem is that all the counters always come back as 0.<br/><br/>I even changed the code to monitor Processor% Processor Time and that always cam back as 0???<br/><br/>here is what i have so far, Hope someone can help.<br/><br/>
<pre>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace PerformanceThreads
{
class Program
{
static void Main(string[] args)
{
string[] instance;
PerformanceCounterCategory myCat = new PerformanceCounterCategory("Thread");
PerformanceCounter counter = new PerformanceCounter("Thread" , "% Processor Time");
instance = myCat.GetInstanceNames();
foreach (string threadInstance in instance)
{
if (threadInstance.Contains("sqlservr"))
{
counter.InstanceName = threadInstance;
Console.WriteLine("Thread: {0} -- Value {1}" , threadInstance , counter.NextValue());
}
}
}
}
}[/code]
View the full article
<pre>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace PerformanceThreads
{
class Program
{
static void Main(string[] args)
{
string[] instance;
PerformanceCounterCategory myCat = new PerformanceCounterCategory("Thread");
PerformanceCounter counter = new PerformanceCounter("Thread" , "% Processor Time");
instance = myCat.GetInstanceNames();
foreach (string threadInstance in instance)
{
if (threadInstance.Contains("sqlservr"))
{
counter.InstanceName = threadInstance;
Console.WriteLine("Thread: {0} -- Value {1}" , threadInstance , counter.NextValue());
}
}
}
}
}[/code]
View the full article