Hi everyone,
I'm trying to create a C# program which monitors the cpu level of vms within virtual server. I've created an event model to captured when the cpu reaches a certain level. What I am getting stuck on is the best way for me to actually poll the vs and determine when the cpu has hit a certain level. tried creating an infinite loop that will constantly pool the cpu level, however I'm never done any kind of thread base programming and my current approach will lock the execution of my program. Can anyone offer any advice on how I would create a monitoring program which constantly polls. If I should use different threads how should I create and manage them? Here is what I have so far and you'lll see why I'm having problems:
public void monitorCpuUtilization()
{
while (true)
{
Thread.Sleep(6000);
if (CPUUsageAverage > 10)
{
dixpatchcpuUtilizationEvent();
}
}
}
Al input welcome. Thanks.
{
System.EventHandler FHandler =
new EventHandler(monitorCpuUti
AsyncCallback Fcallback =
new AsyncCallback(CallBack);
IAsyncResult FResult = FHandler.BeginInvoke(null,
//do other stuff
//after finishing stuff if u want to wait for monitorCpuUtilization to exit
while(!FResult.IsCompleted
{
//infinte loop to wait
}
}
public static void CallBack(IAsyncResult CallBack)
{
// this function is called when monitorCpuUtilization finishes
((System.EventHandler)
((System.Runtime.Remoting.
.EndInvoke(CallBack);
}
public static void monitorCpuUtilization(obje
{
while (true)
{
Thread.Sleep(6000);
if (CPUUsageAverage > 10)
{
dixpatchcpuUtilizationEven
break;//to break the loop
}
}
}