473,288 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,288 software developers and data experts.

Do I produce a handle-leak?

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:_m*************@manfbraun.de
(Remove the anti-spam-underscore to mail me!)
Nov 17 '05 #1
10 2270
Manfred,

Where did you montior this handle increase? Also, what is the type of
handle that you are seeing increasing?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Manfred Braun" <aa@bb.cc> wrote in message
news:up**************@TK2MSFTNGP15.phx.gbl...
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:_m*************@manfbraun.de
(Remove the anti-spam-underscore to mail me!)

Nov 17 '05 #2
Hi Nicholas,

thanks for the interest and sorry for my inaccuracy .... I monitor this with
NT Taskmanager. I use .Net 1.1 and Windows 2000 SP4, en. Just to be sure, I
now went to Perfmon, selected the process and see the same result. The exe
runs since yesterday evening, started an unknown value [until I registered
the problem], then I started to write the numbers down, starting with a
value of 172 and now I am on about 437 .....

Best regards,
Manfred

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@TK2MSFTNGP09.phx.gbl...
Manfred,

Where did you montior this handle increase? Also, what is the type of
handle that you are seeing increasing?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Manfred Braun" <aa@bb.cc> wrote in message
news:up**************@TK2MSFTNGP15.phx.gbl...
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:_m*************@manfbraun.de
(Remove the anti-spam-underscore to mail me!)


Nov 17 '05 #3
Could you post the remaining of this program?

Willy.

"Manfred Braun" <aa@bb.cc> wrote in message
news:up**************@TK2MSFTNGP15.phx.gbl...
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:_m*************@manfbraun.de
(Remove the anti-spam-underscore to mail me!)

Nov 17 '05 #4
Hello,

additional info:I do not know, what TaskManager/Perfomon summarises as
handles .... But from my understanding of my code, nothing should increase
of a not short time.

Regards,
Manfred

"Manfred Braun" <aa@bb.cc> wrote in message
news:u9*************@TK2MSFTNGP12.phx.gbl...
Hi Nicholas,

thanks for the interest and sorry for my inaccuracy .... I monitor this with NT Taskmanager. I use .Net 1.1 and Windows 2000 SP4, en. Just to be sure, I now went to Perfmon, selected the process and see the same result. The exe
runs since yesterday evening, started an unknown value [until I registered
the problem], then I started to write the numbers down, starting with a
value of 172 and now I am on about 437 .....

Best regards,
Manfred

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
Manfred,

Where did you montior this handle increase? Also, what is the type of
handle that you are seeing increasing?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Manfred Braun" <aa@bb.cc> wrote in message
news:up**************@TK2MSFTNGP15.phx.gbl...
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:_m*************@manfbraun.de
(Remove the anti-spam-underscore to mail me!)



Nov 17 '05 #5
Hi,

this proggi is very simple, was just created to see some small/large cpu
load over time. Here it is in full:

Thanks so far and
best regards,
Manfred
===
/*

Name: TP.cs
Author: mb
Created: 15.0.2005
Purpose: Sleep a time, use cpu, sleep
Compile csc /nologo /debug:full /t:exe /out:TP.exe TP.cs

*/

using System;
using System.Diagnostics;
using System.Threading;
using System.Timers;

namespace Test
{
public class Test
{

private System.Timers.Timer timer;
int counter;
public static int Main(string[] args)
{
int rtc = 0;

if(args.Length != 0)
{
Test t = new Test();
t.Run(args);

Console.WriteLine("Press <enter> to exit.");
Console.ReadLine();
}
else
{
Console.WriteLine("Args !!! [P1=Interval{s}]");
rtc = 1;
}

return rtc;
}
private void Run(string[] args)
{
//Create the "Timer"

this.counter = 0;
this.timer = new System.Timers.Timer(Int32.Parse(args[0]) * 1000);
this.timer.Elapsed += new ElapsedEventHandler(this.OnTimer);
this.timer.Enabled = true;
}
private void OnTimer(object sender, ElapsedEventArgs e)
{
Console.WriteLine("TP.OnTimer;Counter:{0}", this.counter);
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

}//class

}//namespace

===

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:ec**************@tk2msftngp13.phx.gbl...
Could you post the remaining of this program?

Willy.

"Manfred Braun" <aa@bb.cc> wrote in message
news:up**************@TK2MSFTNGP15.phx.gbl...
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:_m*************@manfbraun.de
(Remove the anti-spam-underscore to mail me!)


Nov 17 '05 #6
Hello All,

after Nicholas came up with his question, I started Perfmon. Now, I see the
Taskmanager is not a good compagnion for a deeper analyzis :-(

In perfmon, I am seeing a saw tooth, which means, currently, the number of
handles is changinging from a footprint of about 361 up to a max of 461.
I thing the GC collects handles over time. But my start was about 172.

How to interpret this results from perfmon? After I saw the saw tooth, I
think, this is related to CLR and there is really no problem in my code -
that's what I tried to understand, because I think, I really understand my
code ;-)

I'll let Perfom running for a time now.

Thanks,
Manfred

"Manfred Braun" <aa@bb.cc> wrote in message
news:Oo**************@TK2MSFTNGP14.phx.gbl...
Hi,

this proggi is very simple, was just created to see some small/large cpu
load over time. Here it is in full:

Thanks so far and
best regards,
Manfred
===
/*

Name: TP.cs
Author: mb
Created: 15.0.2005
Purpose: Sleep a time, use cpu, sleep
Compile csc /nologo /debug:full /t:exe /out:TP.exe TP.cs

*/

using System;
using System.Diagnostics;
using System.Threading;
using System.Timers;

namespace Test
{
public class Test
{

private System.Timers.Timer timer;
int counter;
public static int Main(string[] args)
{
int rtc = 0;

if(args.Length != 0)
{
Test t = new Test();
t.Run(args);

Console.WriteLine("Press <enter> to exit.");
Console.ReadLine();
}
else
{
Console.WriteLine("Args !!! [P1=Interval{s}]");
rtc = 1;
}

return rtc;
}
private void Run(string[] args)
{
//Create the "Timer"

this.counter = 0;
this.timer = new System.Timers.Timer(Int32.Parse(args[0]) * 1000);
this.timer.Elapsed += new ElapsedEventHandler(this.OnTimer);
this.timer.Enabled = true;
}
private void OnTimer(object sender, ElapsedEventArgs e)
{
Console.WriteLine("TP.OnTimer;Counter:{0}", this.counter);
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

}//class

}//namespace

===

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:ec**************@tk2msftngp13.phx.gbl...
Could you post the remaining of this program?

Willy.

"Manfred Braun" <aa@bb.cc> wrote in message
news:up**************@TK2MSFTNGP15.phx.gbl...
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:_m*************@manfbraun.de
(Remove the anti-spam-underscore to mail me!)



Nov 17 '05 #7
The handles you see are OS Event handles (associated with the timer events),
as your program doesn't create instances of managed classes there is no
memory consumption and the GC wont kick in for a long period of time. As the
Finalizer thread only runs after a GC run, the managed resource (the OS
handle) won't get collected in a timely fashion and the count increases
until the GC kicks in (every 12 minutes, depending on the CLR version, not
100% sure though).

Willy.
"Manfred Braun" <aa@bb.cc> wrote in message
news:us**************@TK2MSFTNGP10.phx.gbl...
Hello All,

after Nicholas came up with his question, I started Perfmon. Now, I see
the
Taskmanager is not a good compagnion for a deeper analyzis :-(

In perfmon, I am seeing a saw tooth, which means, currently, the number of
handles is changinging from a footprint of about 361 up to a max of 461.
I thing the GC collects handles over time. But my start was about 172.

How to interpret this results from perfmon? After I saw the saw tooth, I
think, this is related to CLR and there is really no problem in my code -
that's what I tried to understand, because I think, I really understand my
code ;-)

I'll let Perfom running for a time now.

Thanks,
Manfred

"Manfred Braun" <aa@bb.cc> wrote in message
news:Oo**************@TK2MSFTNGP14.phx.gbl...
Hi,

this proggi is very simple, was just created to see some small/large cpu
load over time. Here it is in full:

Thanks so far and
best regards,
Manfred
===
/*

Name: TP.cs
Author: mb
Created: 15.0.2005
Purpose: Sleep a time, use cpu, sleep
Compile csc /nologo /debug:full /t:exe /out:TP.exe TP.cs

*/

using System;
using System.Diagnostics;
using System.Threading;
using System.Timers;

namespace Test
{
public class Test
{

private System.Timers.Timer timer;
int counter;
public static int Main(string[] args)
{
int rtc = 0;

if(args.Length != 0)
{
Test t = new Test();
t.Run(args);

Console.WriteLine("Press <enter> to exit.");
Console.ReadLine();
}
else
{
Console.WriteLine("Args !!! [P1=Interval{s}]");
rtc = 1;
}

return rtc;
}
private void Run(string[] args)
{
//Create the "Timer"

this.counter = 0;
this.timer = new System.Timers.Timer(Int32.Parse(args[0]) * 1000);
this.timer.Elapsed += new ElapsedEventHandler(this.OnTimer);
this.timer.Enabled = true;
}
private void OnTimer(object sender, ElapsedEventArgs e)
{
Console.WriteLine("TP.OnTimer;Counter:{0}", this.counter);
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

}//class

}//namespace

===

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:ec**************@tk2msftngp13.phx.gbl...
> Could you post the remaining of this program?
>
> Willy.
>
> "Manfred Braun" <aa@bb.cc> wrote in message
> news:up**************@TK2MSFTNGP15.phx.gbl...
> > 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:_m*************@manfbraun.de
> > (Remove the anti-spam-underscore to mail me!)
> >
> >
>
>



Nov 17 '05 #8
Hello Willy and All,

thanks a lot; But you've overseen, that I regularly create an instance of
the Job class, a private class from the Test class, but this is very small.
Thank you for the explanation!
Best regards,
Manfred

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:Oy**************@TK2MSFTNGP09.phx.gbl...
The handles you see are OS Event handles (associated with the timer events), as your program doesn't create instances of managed classes there is no
memory consumption and the GC wont kick in for a long period of time. As the Finalizer thread only runs after a GC run, the managed resource (the OS
handle) won't get collected in a timely fashion and the count increases
until the GC kicks in (every 12 minutes, depending on the CLR version, not
100% sure though).

Willy.
"Manfred Braun" <aa@bb.cc> wrote in message
news:us**************@TK2MSFTNGP10.phx.gbl...
Hello All,

after Nicholas came up with his question, I started Perfmon. Now, I see
the
Taskmanager is not a good compagnion for a deeper analyzis :-(

In perfmon, I am seeing a saw tooth, which means, currently, the number of handles is changinging from a footprint of about 361 up to a max of 461.
I thing the GC collects handles over time. But my start was about 172.

How to interpret this results from perfmon? After I saw the saw tooth, I
think, this is related to CLR and there is really no problem in my code - that's what I tried to understand, because I think, I really understand my code ;-)

I'll let Perfom running for a time now.

Thanks,
Manfred

"Manfred Braun" <aa@bb.cc> wrote in message
news:Oo**************@TK2MSFTNGP14.phx.gbl...
Hi,

this proggi is very simple, was just created to see some small/large cpu load over time. Here it is in full:

Thanks so far and
best regards,
Manfred
===
/*

Name: TP.cs
Author: mb
Created: 15.0.2005
Purpose: Sleep a time, use cpu, sleep
Compile csc /nologo /debug:full /t:exe /out:TP.exe TP.cs

*/

using System;
using System.Diagnostics;
using System.Threading;
using System.Timers;

namespace Test
{
public class Test
{

private System.Timers.Timer timer;
int counter;
public static int Main(string[] args)
{
int rtc = 0;

if(args.Length != 0)
{
Test t = new Test();
t.Run(args);

Console.WriteLine("Press <enter> to exit.");
Console.ReadLine();
}
else
{
Console.WriteLine("Args !!! [P1=Interval{s}]");
rtc = 1;
}

return rtc;
}
private void Run(string[] args)
{
//Create the "Timer"

this.counter = 0;
this.timer = new System.Timers.Timer(Int32.Parse(args[0]) * 1000);
this.timer.Elapsed += new ElapsedEventHandler(this.OnTimer);
this.timer.Enabled = true;
}
private void OnTimer(object sender, ElapsedEventArgs e)
{
Console.WriteLine("TP.OnTimer;Counter:{0}", this.counter);
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

}//class

}//namespace

===

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:ec**************@tk2msftngp13.phx.gbl...
> Could you post the remaining of this program?
>
> Willy.
>
> "Manfred Braun" <aa@bb.cc> wrote in message
> news:up**************@TK2MSFTNGP15.phx.gbl...
> > 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:_m*************@manfbraun.de
> > (Remove the anti-spam-underscore to mail me!)
> >
> >
>
>




Nov 17 '05 #9
Manfred,
Right, Hmmm ... let's see 12 bytes per instance, say the Gen0 threshold is
256 Kb, that means a collection per 22000 instances and one instance per 10
secs, makes a collection per 220000 secs ;-).
Willy.

"Manfred Braun" <aa@bb.cc> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hello Willy and All,

thanks a lot; But you've overseen, that I regularly create an instance of
the Job class, a private class from the Test class, but this is very
small.
Thank you for the explanation!
Best regards,
Manfred

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:Oy**************@TK2MSFTNGP09.phx.gbl...
The handles you see are OS Event handles (associated with the timer

events),
as your program doesn't create instances of managed classes there is no
memory consumption and the GC wont kick in for a long period of time. As

the
Finalizer thread only runs after a GC run, the managed resource (the OS
handle) won't get collected in a timely fashion and the count increases
until the GC kicks in (every 12 minutes, depending on the CLR version,
not
100% sure though).

Willy.
"Manfred Braun" <aa@bb.cc> wrote in message
news:us**************@TK2MSFTNGP10.phx.gbl...
> Hello All,
>
> after Nicholas came up with his question, I started Perfmon. Now, I see
> the
> Taskmanager is not a good compagnion for a deeper analyzis :-(
>
> In perfmon, I am seeing a saw tooth, which means, currently, the number of > handles is changinging from a footprint of about 361 up to a max of
> 461.
> I thing the GC collects handles over time. But my start was about 172.
>
> How to interpret this results from perfmon? After I saw the saw tooth,
> I
> think, this is related to CLR and there is really no problem in my code - > that's what I tried to understand, because I think, I really understand my > code ;-)
>
> I'll let Perfom running for a time now.
>
> Thanks,
> Manfred
>
> "Manfred Braun" <aa@bb.cc> wrote in message
> news:Oo**************@TK2MSFTNGP14.phx.gbl...
>> Hi,
>>
>> this proggi is very simple, was just created to see some small/large cpu >> load over time. Here it is in full:
>>
>> Thanks so far and
>> best regards,
>> Manfred
>> ===
>> /*
>>
>> Name: TP.cs
>> Author: mb
>> Created: 15.0.2005
>> Purpose: Sleep a time, use cpu, sleep
>> Compile csc /nologo /debug:full /t:exe /out:TP.exe TP.cs
>>
>> */
>>
>> using System;
>> using System.Diagnostics;
>> using System.Threading;
>> using System.Timers;
>>
>>
>>
>> namespace Test
>> {
>>
>>
>> public class Test
>> {
>>
>> private System.Timers.Timer timer;
>> int counter;
>>
>>
>> public static int Main(string[] args)
>> {
>> int rtc = 0;
>>
>> if(args.Length != 0)
>> {
>> Test t = new Test();
>> t.Run(args);
>>
>> Console.WriteLine("Press <enter> to exit.");
>> Console.ReadLine();
>> }
>> else
>> {
>> Console.WriteLine("Args !!! [P1=Interval{s}]");
>> rtc = 1;
>> }
>>
>> return rtc;
>> }
>>
>>
>> private void Run(string[] args)
>> {
>> //Create the "Timer"
>>
>> this.counter = 0;
>> this.timer = new System.Timers.Timer(Int32.Parse(args[0]) * 1000);
>> this.timer.Elapsed += new ElapsedEventHandler(this.OnTimer);
>> this.timer.Enabled = true;
>> }
>>
>>
>> private void OnTimer(object sender, ElapsedEventArgs e)
>> {
>> Console.WriteLine("TP.OnTimer;Counter:{0}", this.counter);
>> 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
>>
>> }//class
>>
>>
>>
>> }//namespace
>>
>> ===
>>
>> "Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
>> news:ec**************@tk2msftngp13.phx.gbl...
>> > Could you post the remaining of this program?
>> >
>> > Willy.
>> >
>> > "Manfred Braun" <aa@bb.cc> wrote in message
>> > news:up**************@TK2MSFTNGP15.phx.gbl...
>> > > 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:_m*************@manfbraun.de
>> > > (Remove the anti-spam-underscore to mail me!)
>> > >
>> > >
>> >
>> >
>>
>>
>
>



Nov 17 '05 #10
Willy,

ahh! In the meantime, I added the Workingset to Perfmon, but this shows a
nearly constant line [over the sort time of the last 90 mintes], which is
now explained by you !!!

Thanks a lot,
Manfred

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:O3**************@TK2MSFTNGP10.phx.gbl...
Manfred,
Right, Hmmm ... let's see 12 bytes per instance, say the Gen0 threshold is
256 Kb, that means a collection per 22000 instances and one instance per 10 secs, makes a collection per 220000 secs ;-).
Willy.

"Manfred Braun" <aa@bb.cc> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hello Willy and All,

thanks a lot; But you've overseen, that I regularly create an instance of the Job class, a private class from the Test class, but this is very
small.
Thank you for the explanation!
Best regards,
Manfred

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:Oy**************@TK2MSFTNGP09.phx.gbl...
The handles you see are OS Event handles (associated with the timer

events),
as your program doesn't create instances of managed classes there is no
memory consumption and the GC wont kick in for a long period of time. As
the
Finalizer thread only runs after a GC run, the managed resource (the OS
handle) won't get collected in a timely fashion and the count increases
until the GC kicks in (every 12 minutes, depending on the CLR version,
not
100% sure though).

Willy.
"Manfred Braun" <aa@bb.cc> wrote in message
news:us**************@TK2MSFTNGP10.phx.gbl...
> Hello All,
>
> after Nicholas came up with his question, I started Perfmon. Now, I
see > the
> Taskmanager is not a good compagnion for a deeper analyzis :-(
>
> In perfmon, I am seeing a saw tooth, which means, currently, the number of
> handles is changinging from a footprint of about 361 up to a max of
> 461.
> I thing the GC collects handles over time. But my start was about
172. >
> How to interpret this results from perfmon? After I saw the saw tooth, > I
> think, this is related to CLR and there is really no problem in my

code -
> that's what I tried to understand, because I think, I really understand my
> code ;-)
>
> I'll let Perfom running for a time now.
>
> Thanks,
> Manfred
>
> "Manfred Braun" <aa@bb.cc> wrote in message
> news:Oo**************@TK2MSFTNGP14.phx.gbl...
>> Hi,
>>
>> this proggi is very simple, was just created to see some small/large

cpu
>> load over time. Here it is in full:
>>
>> Thanks so far and
>> best regards,
>> Manfred
>> ===
>> /*
>>
>> Name: TP.cs
>> Author: mb
>> Created: 15.0.2005
>> Purpose: Sleep a time, use cpu, sleep
>> Compile csc /nologo /debug:full /t:exe /out:TP.exe TP.cs
>>
>> */
>>
>> using System;
>> using System.Diagnostics;
>> using System.Threading;
>> using System.Timers;
>>
>>
>>
>> namespace Test
>> {
>>
>>
>> public class Test
>> {
>>
>> private System.Timers.Timer timer;
>> int counter;
>>
>>
>> public static int Main(string[] args)
>> {
>> int rtc = 0;
>>
>> if(args.Length != 0)
>> {
>> Test t = new Test();
>> t.Run(args);
>>
>> Console.WriteLine("Press <enter> to exit.");
>> Console.ReadLine();
>> }
>> else
>> {
>> Console.WriteLine("Args !!! [P1=Interval{s}]");
>> rtc = 1;
>> }
>>
>> return rtc;
>> }
>>
>>
>> private void Run(string[] args)
>> {
>> //Create the "Timer"
>>
>> this.counter = 0;
>> this.timer = new System.Timers.Timer(Int32.Parse(args[0]) * 1000);
>> this.timer.Elapsed += new ElapsedEventHandler(this.OnTimer);
>> this.timer.Enabled = true;
>> }
>>
>>
>> private void OnTimer(object sender, ElapsedEventArgs e)
>> {
>> Console.WriteLine("TP.OnTimer;Counter:{0}", this.counter);
>> 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
>>
>> }//class
>>
>>
>>
>> }//namespace
>>
>> ===
>>
>> "Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in

message >> news:ec**************@tk2msftngp13.phx.gbl...
>> > Could you post the remaining of this program?
>> >
>> > Willy.
>> >
>> > "Manfred Braun" <aa@bb.cc> wrote in message
>> > news:up**************@TK2MSFTNGP15.phx.gbl...
>> > > 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:_m*************@manfbraun.de
>> > > (Remove the anti-spam-underscore to mail me!)
>> > >
>> > >
>> >
>> >
>>
>>
>
>



Nov 17 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: flupke | last post by:
Hi, i am in search of a cddb module for Python on windows. I stumbled upon http://sourceforge.net/projects/cddb-py but couldn't use it since the mci.dll is compiled against Python2.0. So i'm...
3
by: mydirac | last post by:
hello, I'm thinking about javascript's producing another file. Can I do it?
58
by: Jeff_Relf | last post by:
Hi Tom, You showed: << private const string PHONE_LIST = "495.1000__424.1111___(206)564-5555_1.800.325.3333"; static void Main( string args ) { foreach (string phoneNumber in Regex.Split...
1
by: Henro V | last post by:
I am byuilding this database which (among others things) will have to produce a kind of calendar. Users give in the appointments they have and how long they take. F.e: John Doe is attending a...
3
by: Amelyan | last post by:
When we want radio button to belong to a group name we say, radio1.GroupName="GroupA". In this case, radio1 will be unselected if another radio button is selected in "GroupA". Is there a way...
14
by: Tom.PesterDELETETHISSS | last post by:
Hi, I think this question requires an in depth understanding of how a browser cache works. I hope I can reach an expert here. I may have found a quirk in the asp.net documentation or I don't...
9
by: Charles Law | last post by:
I have asked a similar question to this before, but have not found a satisfactory answer yet, so I thought I would ask it in another way. KeyPreview, for a form, handily allows keys to be...
3
by: Agnes | last post by:
My client said when he got "Timeout Expired", once he press the button. whole applciation is quit. I want to "produce the same error " in my development environment but don't know how to do ?...
7
by: needin4mation | last post by:
Hi, I have a simple web service. In my HelloWorld() all it does it retreive about five last and first names from a database. It then returns the DataSet. When I run the Web Service in VS 2003...
25
by: tooru honda | last post by:
Hi, I have read the source code of the built-in random module, random.py. After also reading Wiki article on Knuth Shuffle algorithm, I wonder if the shuffle method implemented in random.py...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.