Threads that do not end

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm developing an application that makes a lot of assyncronous things. I
always use the methods BeginXXX and EndXXX when they are available or
BeginInvoke and EndInvoke when they are not available. I never use the
Thread.Start() method.
What happens is that the number of threads shown in Task Manager grows up
and after some days there are thousands of threads. I can't find a reason for
this behaviour. Could anyone help me?
 
u can't really run 1000's of threads. where are you seeing that reading? and
what does it have to do with your application?

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
 
Hi Ricardo,

You have to make sure tha you call EndXXX or EndInvoke, for every BeginXXX,
or BeginInvoke, otherwise your workerthreads will nevere release their
associated resources...

Tibi
 
I've read in the MSDN that these methods run on the thread pool. However,
there are something like 1400 threads and 9900 handles. I've seen these
number on Task Manager (go to the View menu and choose Select Columns. Check
the Handle Count and Thread Count items).

Alvin Bruney - ASP.NET MVP said:
u can't really run 1000's of threads. where are you seeing that reading? and
what does it have to do with your application?

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------



Ricardo said:
I'm developing an application that makes a lot of assyncronous things. I
always use the methods BeginXXX and EndXXX when they are available or
BeginInvoke and EndInvoke when they are not available. I never use the
Thread.Start() method.
What happens is that the number of threads shown in Task Manager grows up
and after some days there are thousands of threads. I can't find a reason for
this behaviour. Could anyone help me?
 
Tiberiu Covaci said:
You have to make sure tha you call EndXXX or EndInvoke, for every BeginXXX,
or BeginInvoke, otherwise your workerthreads will nevere release their
associated resources...

Note that although that's true for most Begin/End pairings, it *isn't*
true for Control.BeginInvoke/EndInvoke - you don't need to worry about
calling EndInvoke.
 
Tiberiu Covaci said:
But I see calling EndInvoke as a best practice, anyway....

I don't see why, for Control.BeginInvoke. It's not required and has
been guaranteed by the WinForms team not to cause a leak, and often
it's a bit of a pain to get one in there. Admittedly you can have a
"fire and forget" pattern which just adds the EndInvoke for you, but
even using that decreases the readability for no gain.
 
You have to make sure tha you call EndXXX or EndInvoke, for every
BeginXXX, or BeginInvoke, otherwise your workerthreads will nevere release
their associated resources...
I think these asynchronous method call are a pain in the neck
I had a quick glance it and wondered: why go through this lengthy / tedious
/ complex BeginInvoke/EndInvoke (which add plenty of parameters and stuff)
when firing up a thread and synchronizing it myself was so much more simple
.....
not too mention it's a breeze with anonymous delegate
did I miss something?
 
Oops.. never mind...
I should have been much tired the day they annoyed me.

Yet with anonymous delegate makes multithreading extremely simple
 
Back
Top