M
Manfred Braun
Hi All,
I am writing a proggi, which should monitor some processes. While doing
this, I needed a test-program and wrote one, which does nothing else than to
consume some cpu, sometimes more, sometimes less. As I monitored this
process for a time, I found the handles increasing without end. I assume
this is a bug, but I do not understand, where this could be located in my
simple app. The core is as follows:
private void OnTimer(object sender, ElapsedEventArgs e) //fires every 10
seconds
{
int steps = 0;
this.counter++;
this.counter = this.counter % 10;
if(this.counter == 4)
{
steps = 1000;
}
else
{
if(this.counter == 9)
{
steps = 10000000;
}
}
if(steps != 0)
{
Job j = new Job(steps);
ThreadStart ts = new ThreadStart(j.Run);
Thread t = new Thread(ts);
t.IsBackground = true;
t.Start();
}
}
private class Job
{
private int steps;
public Job(int steps)
{ this.steps = steps; }
public void Run()
{
Console.WriteLine("Job.Run;Steps:{0}", this.steps);
//Consume some cpu
for(int i = 0; i < this.steps;i++);
}
}//class
The number of threads is stable in this program [as I expect], the handles
are increasing endless. Where is my fault? And what are these handles?
Some help would really be very welcomed!!
Best regards,
Manfred Braun
(Private)
Mannheim
Germany
mailto:[email protected]
(Remove the anti-spam-underscore to mail me!)
I am writing a proggi, which should monitor some processes. While doing
this, I needed a test-program and wrote one, which does nothing else than to
consume some cpu, sometimes more, sometimes less. As I monitored this
process for a time, I found the handles increasing without end. I assume
this is a bug, but I do not understand, where this could be located in my
simple app. The core is as follows:
private void OnTimer(object sender, ElapsedEventArgs e) //fires every 10
seconds
{
int steps = 0;
this.counter++;
this.counter = this.counter % 10;
if(this.counter == 4)
{
steps = 1000;
}
else
{
if(this.counter == 9)
{
steps = 10000000;
}
}
if(steps != 0)
{
Job j = new Job(steps);
ThreadStart ts = new ThreadStart(j.Run);
Thread t = new Thread(ts);
t.IsBackground = true;
t.Start();
}
}
private class Job
{
private int steps;
public Job(int steps)
{ this.steps = steps; }
public void Run()
{
Console.WriteLine("Job.Run;Steps:{0}", this.steps);
//Consume some cpu
for(int i = 0; i < this.steps;i++);
}
}//class
The number of threads is stable in this program [as I expect], the handles
are increasing endless. Where is my fault? And what are these handles?
Some help would really be very welcomed!!
Best regards,
Manfred Braun
(Private)
Mannheim
Germany
mailto:[email protected]
(Remove the anti-spam-underscore to mail me!)