Reputation: 1020
I have engineered a process monitor which works fine but after 5 or 6 hours it takes 100% CPU usage.on physical PC it works fine but on VM it takes 100% usage.plz tell me what is the problem.coding part has two threads one for deleting the closed process and one is for capture the new process.
private void getPorcess()
{
int pid=0;
int pid1=0;
ArrayList oProList1 = new ArrayList();
ArrayList oProList2 = new ArrayList();
while (true)
{
Process[] oPrcs = Process.GetProcesses();
if (oPrcs.Length < oProList1.Count)
{
foreach (Process pr1 in oPrcs)
{
pid1 = pr1.Id;
string p = pr1.ProcessName;
oProList2.Add(pid1);
}
//MessageBox.Show(oProList2.Count.ToString());
oProList1.Clear();
oProList1.AddRange(oProList2);
oProList2.Clear();
}
foreach (Process pr in oPrcs)
{
pid = pr.Id;
if (!oProList1.Contains(pid))
{
oProList1.Add(pid);
string szres = "";
try
{
string prcsname = pr.Modules[0].FileName;
if ("")
{
}
}
catch
{
}
}
}
Thread.Sleep(100);
}
}
Upvotes: 0
Views: 329
Reputation: 33197
plz tell me what is the problem
A bug which causes it to use 100% of your CPU.
You should fix this bug to make it not use 100% of your CPU.
Upvotes: 4