我是否会产生手柄泄漏? [英] Do I produce a handle-leak?
问题描述
大家好,
我正在写一个proggi,它应该监视一些进程。在做这个的时候,我需要一个测试程序,然后编写一个,除了使用
消耗一些cpu,有时候更多,有时更少,只需要一个测试程序。当我监视这个
进程一段时间后,我发现句柄不断增加。我假设
这是一个错误,但我不明白,这可能位于我的
简单应用程序中。核心如下:
private void OnTimer(对象发送者,ElapsedEventArgs e)//每10次触发
秒
{
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)
{
工作j =新工作(步骤);
ThreadStart ts = new ThreadStart(j.Run);
线程t =新线程(ts);
t.IsBackground = true;
t.Start();
}
}
私人课程工作
{
private int steps;
public Job(int steps)
{this.steps = steps; }
public void Run()
{
Console.WriteLine(" Job.Run; Steps:{0} ",this.steps);
//消耗一些cpu
for(int i = 0; i< this.steps ; i ++);
}
} //类
此程序中线程数稳定[正如我所料],手柄
正在不断增加。我的错在哪里?这些手柄是什么?
一些帮助非常欢迎!!
祝你好运,
Manfred Braun
(私人)
曼海姆
德国
mailto:_m **** *********@manfbraun.de
(删除反垃圾邮件下划线给我发邮件!)
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!)
推荐答案
Manfred,
你在哪里监督这个句柄的增加?另外,你看到的
手柄的类型是什么?
-
- Nicholas Paldino [.NET / C#MVP]
- mv*@spam.guard.caspershouse.com
" Manfred Braun" < aa@bb.cc>在消息中写道
news:up ************** @ TK2MSFTNGP15.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...
大家好,
消耗一些cpu,有时更多,有时更少,它什么也没做。当我监视这个过程一段时间后,我发现手柄不断增加。我假设
这是一个错误,但我不明白,这可能位于我的
简单应用程序中。核心如下:
private void OnTimer(对象发送者,ElapsedEventArgs e)//每10秒触发一次
{
int steps = 0;
this.counter ++;
this.counter = this.counter%10;
if(this.counter == 4)
{
steps = 1000;
}
{
if(this.counter == 9)
{
steps = 10000000;
}
}
如果(步骤!= 0)
{
工作j =新工作(步骤);
ThreadStart ts = new ThreadStart(j.Run);
线程t =新线程(ts);
t.IsBackground = true;
t.Start();
}
}
私人班级工作
{private int steps;
公共工作(国际公司的步骤)
{this.steps =步骤; }
public void Run()
{
Console.WriteLine(" Job.Run; Steps:{0}",this.steps);
//消耗一些cpu
for(int i = 0; i< this.steps; i ++);
}
} // class
这个程序中线程的数量是稳定的[正如我所料],句柄
正在不断增加。我的错在哪里?这些手柄是什么?
一些帮助真的非常受欢迎!!
此致敬意,
曼弗雷德布劳恩
(私人)>曼海姆
德国
mailto:_m ************* @ manfbraun.de
(删除反垃圾邮件下划线给我发邮件!)
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!)
嗨尼古拉斯,
感谢您的关注和抱歉我的不准确。 ...我用
NT Taskmanager来监控它。我使用.Net 1.1和Windows 2000 SP4,en。只是为了确定,我现在转到Perfmon,选择了这个过程并看到了相同的结果。自从昨天晚上开始运行一个未知的值[直到我注册了问题],然后我开始写下数字,从
价值172,现在我约437 .....
祝你好运,
Manfred
Nicholas Paldino [.NET / C#MVP]" < mv*@spam.guard.caspershouse.com>写在
消息新闻:%2 **************** @ TK2MSFTNGP09.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,
你在哪里监督这个句柄增加了?另外,你看到的手柄类型有多少?
-
- Nicholas Paldino [.NET / C#MVP]
- mv*@spam.guard.caspershouse.com
Manfred Braun < aa@bb.cc>在消息中写道
新闻:up ************** @ TK2MSFTNGP15.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...
大家好,
。当我监视这个过程一段时间后,我发现手柄不断增加。我假设
这是一个错误,但我不明白,这可能位于
我的简单应用程序中。核心如下:
private void OnTimer(对象发送者,ElapsedEventArgs e)//每10秒触发一次
{
int steps = 0;
this.counter ++;
this.counter = this.counter%10;
if(this.counter == 4)
{
steps = 1000;
}
{
if(this.counter == 9)
{
steps = 10000000;
}
}
如果(步骤!= 0)
{
工作j =新工作(步骤);
ThreadStart ts = new ThreadStart(j.Run);
线程t =新线程(ts);
t.IsBackground = true;
t.Start();
}
}
私人班级工作
{private int steps;
公共工作(国际公司的步骤)
{this.steps =步骤; }
public void Run()
{
Console.WriteLine(" Job.Run; Steps:{0}",this.steps);
//消耗一些cpu
for(int i = 0; i< this.steps; i ++);
}
} // class
线程数在这个程序中是稳定的[正如我所料],
句柄越来越多。我的错在哪里?这些手柄是什么?
一些帮助真的非常受欢迎!!
此致敬意,
曼弗雷德布劳恩
(私人)>曼海姆
德国
mailto:_m ************* @ manfbraun.de
(删除反垃圾邮件下划线给我发邮件!)
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!)
你能发布这个程序的剩余部分吗?
Willy。
" Manfred Braun" < aa@bb.cc>在消息中写道
news:up ************** @ TK2MSFTNGP15.phx.gbl ...
Could you post the remaining of this program?
Willy.
"Manfred Braun" <aa@bb.cc> wrote in message
news:up**************@TK2MSFTNGP15.phx.gbl...
大家好,
消耗一些cpu,有时更多,有时更少,它什么也没做。当我监视这个过程一段时间后,我发现手柄不断增加。我假设
这是一个错误,但我不明白,这可能位于我的
简单应用程序中。核心如下:
private void OnTimer(对象发送者,ElapsedEventArgs e)//每10秒触发一次
{
int steps = 0;
this.counter ++;
this.counter = this.counter%10;
if(this.counter == 4)
{
steps = 1000;
}
{
if(this.counter == 9)
{
steps = 10000000;
}
}
如果(步骤!= 0)
{
工作j =新工作(步骤);
ThreadStart ts = new ThreadStart(j.Run);
线程t =新线程(ts);
t.IsBackground = true;
t.Start();
}
}
私人班级工作
{private int steps;
公共工作(国际公司的步骤)
{this.steps =步骤; }
public void Run()
{
Console.WriteLine(" Job.Run; Steps:{0}",this.steps);
//消耗一些cpu
for(int i = 0; i< this.steps; i ++);
}
} // class
这个程序中线程的数量是稳定的[正如我所料],句柄
正在不断增加。我的错在哪里?这些手柄是什么?
一些帮助真的非常受欢迎!!
此致敬意,
曼弗雷德布劳恩
(私人)>曼海姆
德国
mailto:_m ************* @ manfbraun.de
(删除反垃圾邮件下划线给我发邮件!)
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!)
这篇关于我是否会产生手柄泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!