473,385 Members | 1,337 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,385 software developers and data experts.

threadpool

We are queueing stuff on the thread pool and what we are queueing gets done
pretty quick (the method returns fine) but yet its only allowed to run
around 25 times, is there anything I need to do to tell the threadpool that
my method is done running and the thread is to be disposed of?
Nov 13 '05 #1
8 4789
memememe,

What do you mean that it is only allowed to run 25 times? Do you mean
that you can only have 25 concurrent activities at the same time?

The thread pool has a limit on the number of threads that can run at one
time from it. The max is determined by the number of processors, for each
processor on the machine, 25 threads are allowed in the thread pool.

Also, when your method is done, it will cause the thread pool thread to
be sent back to the pool, to be reused later. It should not die. This is
done to improve performance and reduce the overhead from initializing new
threads.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com
"memememe" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
news:bo*********************@news1.central.cox.net ...
We are queueing stuff on the thread pool and what we are queueing gets done pretty quick (the method returns fine) but yet its only allowed to run
around 25 times, is there anything I need to do to tell the threadpool that my method is done running and the thread is to be disposed of?

Nov 13 '05 #2

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:ux*************@tk2msftngp13.phx.gbl...
memememe,

What do you mean that it is only allowed to run 25 times? Do you mean
that you can only have 25 concurrent activities at the same time?

The thread pool has a limit on the number of threads that can run at one time from it. The max is determined by the number of processors, for each
processor on the machine, 25 threads are allowed in the thread pool.

Also, when your method is done, it will cause the thread pool thread to be sent back to the pool, to be reused later. It should not die. This is
done to improve performance and reduce the overhead from initializing new
threads.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com
"memememe" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
news:bo*********************@news1.central.cox.net ...
We are queueing stuff on the thread pool and what we are queueing gets

done
pretty quick (the method returns fine) but yet its only allowed to run
around 25 times, is there anything I need to do to tell the threadpool

that
my method is done running and the thread is to be disposed of?


sorry I should have been clearer.
We queue up a lot of work, more than 25, lets say 1k. We see the first 25
threads get executed, then they end, once they end no more work on the queue
gets executed, the threads in use are 25, the available threads are 0, but
our method ends and returns, so I am not sure what else we have to do to
tell the thread pool to go ahead and reuse the thread.
Nov 13 '05 #3

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:Ot**************@TK2MSFTNGP11.phx.gbl...
memememe,

How are you determining that the threads are not being reused? Once the work item is complete, the thread should go back to the pool.

Also, the thread pool is used by other parts of the framework, and it
doesn't just run the threads whenever. It also takes other factors into
consideration when deciding which items to perform work on.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"memememe" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
news:DU*********************@news1.central.cox.net ...

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:ux*************@tk2msftngp13.phx.gbl...
memememe,

What do you mean that it is only allowed to run 25 times? Do you mean that you can only have 25 concurrent activities at the same time?

The thread pool has a limit on the number of threads that can run at
one
time from it. The max is determined by the number of processors, for each processor on the machine, 25 threads are allowed in the thread pool.

Also, when your method is done, it will cause the thread pool
thread
to
be sent back to the pool, to be reused later. It should not die.
This is done to improve performance and reduce the overhead from initializing new threads.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com
"memememe" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
news:bo*********************@news1.central.cox.net ...
> We are queueing stuff on the thread pool and what we are queueing

gets done
> pretty quick (the method returns fine) but yet its only allowed to run > around 25 times, is there anything I need to do to tell the threadpool that
> my method is done running and the thread is to be disposed of?
>
>

sorry I should have been clearer.
We queue up a lot of work, more than 25, lets say 1k. We see the first

25 threads get executed, then they end, once they end no more work on the

queue
gets executed, the threads in use are 25, the available threads are 0, but our method ends and returns, so I am not sure what else we have to do to
tell the thread pool to go ahead and reuse the thread.



well its a very simple program.
It queues up stuff to do on the threadpool (way more than 25) then it does
the stuff, I print out at the end of the method when its done processing,
and it exits fine, this happens for 25 times. There is nothing else running
on the system, its just a simple simple program, but I imagine once the
method is done running it should trhow the thread back on the queue? or do I
need to tell the thread pool that im done running that method?
Nov 13 '05 #4
memememe,

You don't have to tell the ThreadPool class anything when you are done,
it will know when you are done.

Can you post your code, and we can take a look at it?
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"memememe" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
news:i7*********************@news1.central.cox.net ...

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote in message news:Ot**************@TK2MSFTNGP11.phx.gbl...
memememe,

How are you determining that the threads are not being reused? Once the
work item is complete, the thread should go back to the pool.

Also, the thread pool is used by other parts of the framework, and it
doesn't just run the threads whenever. It also takes other factors into
consideration when deciding which items to perform work on.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"memememe" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
news:DU*********************@news1.central.cox.net ...

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com>

wrote
in message news:ux*************@tk2msftngp13.phx.gbl...
> memememe,
>
> What do you mean that it is only allowed to run 25 times? Do you
mean
> that you can only have 25 concurrent activities at the same time?
>
> The thread pool has a limit on the number of threads that can
run at one
> time from it. The max is determined by the number of processors,
for each
> processor on the machine, 25 threads are allowed in the thread pool.
>
> Also, when your method is done, it will cause the thread pool thread to
> be sent back to the pool, to be reused later. It should not die. This
is
> done to improve performance and reduce the overhead from
initializing new
> threads.
>
> Hope this helps.
>
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - ni**************@exisconsulting.com
>
>
> "memememe" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
> news:bo*********************@news1.central.cox.net ...
> > We are queueing stuff on the thread pool and what we are queueing

gets > done
> > pretty quick (the method returns fine) but yet its only allowed to run > > around 25 times, is there anything I need to do to tell the threadpool > that
> > my method is done running and the thread is to be disposed of?
> >
> >
>
>
sorry I should have been clearer.
We queue up a lot of work, more than 25, lets say 1k. We see the first 25 threads get executed, then they end, once they end no more work on the

queue
gets executed, the threads in use are 25, the available threads are 0, but our method ends and returns, so I am not sure what else we have to do

to tell the thread pool to go ahead and reuse the thread.



well its a very simple program.
It queues up stuff to do on the threadpool (way more than 25) then it does
the stuff, I print out at the end of the method when its done processing,
and it exits fine, this happens for 25 times. There is nothing else

running on the system, its just a simple simple program, but I imagine once the
method is done running it should trhow the thread back on the queue? or do I need to tell the thread pool that im done running that method?

Nov 13 '05 #5

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:OG****************@tk2msftngp13.phx.gbl...
memememe,

You don't have to tell the ThreadPool class anything when you are done, it will know when you are done.

Can you post your code, and we can take a look at it?
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"memememe" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
news:i7*********************@news1.central.cox.net ...

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:Ot**************@TK2MSFTNGP11.phx.gbl...
memememe,

How are you determining that the threads are not being reused? Once
the
work item is complete, the thread should go back to the pool.

Also, the thread pool is used by other parts of the framework, and it doesn't just run the threads whenever. It also takes other factors
into consideration when deciding which items to perform work on.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"memememe" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
news:DU*********************@news1.central.cox.net ...
>
> "Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
> in message news:ux*************@tk2msftngp13.phx.gbl...
> > memememe,
> >
> > What do you mean that it is only allowed to run 25 times? Do you mean
> > that you can only have 25 concurrent activities at the same time?
> >
> > The thread pool has a limit on the number of threads that can run
at
> one
> > time from it. The max is determined by the number of processors,

for each
> > processor on the machine, 25 threads are allowed in the thread pool. > >
> > Also, when your method is done, it will cause the thread pool

thread
> to
> > be sent back to the pool, to be reused later. It should not die.

This
is
> > done to improve performance and reduce the overhead from initializing new
> > threads.
> >
> > Hope this helps.
> >
> >
> > --
> > - Nicholas Paldino [.NET/C# MVP]
> > - ni**************@exisconsulting.com
> >
> >
> > "memememe" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
> > news:bo*********************@news1.central.cox.net ...
> > > We are queueing stuff on the thread pool and what we are queueing gets
> > done
> > > pretty quick (the method returns fine) but yet its only allowed
to
run
> > > around 25 times, is there anything I need to do to tell the

threadpool
> > that
> > > my method is done running and the thread is to be disposed of?
> > >
> > >
> >
> >
>
>
> sorry I should have been clearer.
> We queue up a lot of work, more than 25, lets say 1k. We see the
first 25
> threads get executed, then they end, once they end no more work on
the queue
> gets executed, the threads in use are 25, the available threads are

0, but
> our method ends and returns, so I am not sure what else we have to
do to > tell the thread pool to go ahead and reuse the thread.
>
>
well its a very simple program.
It queues up stuff to do on the threadpool (way more than 25) then it

does the stuff, I print out at the end of the method when its done processing, and it exits fine, this happens for 25 times. There is nothing else

running
on the system, its just a simple simple program, but I imagine once the
method is done running it should trhow the thread back on the queue? or

do I
need to tell the thread pool that im done running that method?



thanks for the help, i have a feeling there is something hanging the code
somewhere else, its not my code (bosses) so I cant post, nor do I know where
the problem might be, the thread thing I posted was the first thing I
noticed, I will check a little further. Thanks again
Nov 13 '05 #6
On Tue, 08 Jul 2003 18:32:46 GMT, "memememe"
<[rem]casolorz[rem]@hot[rem]mail.com> wrote:

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:Ot**************@TK2MSFTNGP11.phx.gbl...
memememe,

How are you determining that the threads are not being reused? Once

the
work item is complete, the thread should go back to the pool.

Also, the thread pool is used by other parts of the framework, and it
doesn't just run the threads whenever. It also takes other factors into
consideration when deciding which items to perform work on.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"memememe" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
news:DU*********************@news1.central.cox.net ...
>
> "Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com>

wrote
> in message news:ux*************@tk2msftngp13.phx.gbl...
> > memememe,
> >
> > What do you mean that it is only allowed to run 25 times? Do you

mean
> > that you can only have 25 concurrent activities at the same time?
> >
> > The thread pool has a limit on the number of threads that can runat > one
> > time from it. The max is determined by the number of processors, for

each
> > processor on the machine, 25 threads are allowed in the thread pool.
> >
> > Also, when your method is done, it will cause the thread poolthread > to
> > be sent back to the pool, to be reused later. It should not die.This
is
> > done to improve performance and reduce the overhead from initializing

new
> > threads.
> >
> > Hope this helps.
> >
> >
> > --
> > - Nicholas Paldino [.NET/C# MVP]
> > - ni**************@exisconsulting.com
> >
> >
> > "memememe" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
> > news:bo*********************@news1.central.cox.net ...
> > > We are queueing stuff on the thread pool and what we are queueing

gets > > done
> > > pretty quick (the method returns fine) but yet its only allowed torun > > > around 25 times, is there anything I need to do to tell thethreadpool > > that
> > > my method is done running and the thread is to be disposed of?
> > >
> > >
> >
> >
>
>
> sorry I should have been clearer.
> We queue up a lot of work, more than 25, lets say 1k. We see the first25 > threads get executed, then they end, once they end no more work on the

queue
> gets executed, the threads in use are 25, the available threads are 0,but > our method ends and returns, so I am not sure what else we have to do to
> tell the thread pool to go ahead and reuse the thread.
>
>



well its a very simple program.
It queues up stuff to do on the threadpool (way more than 25) then it does
the stuff, I print out at the end of the method when its done processing,
and it exits fine, this happens for 25 times. There is nothing else running
on the system, its just a simple simple program, but I imagine once the
method is done running it should trhow the thread back on the queue? or do I
need to tell the thread pool that im done running that method?

My experience has been that if a thread is not available because they
are all in use, it throws some sort of exception (which may be handled
internally) and the request just goes away. It doesn't appear to
queue them up.

Of course, I could be wrong about that but that has been my
experience.

What I do is increment a counter each time I queue a threadpool
thread. When that thread finishes, I decrement the thread count. You
can use the Interlocked class to do this.

You get 25 threads per CPU, but some of them may be used by the
framework. So, before I queue up, I check to make sure I have several
threads left. If I don't, I go to sleep for a second or two, and keep
checking in a loop until I have enough threads available. When there
are enough, I queue up another thread.

Also, if you main thread ends while threadpool threads are running,
they will be aborted, so before I leave my routine, I make sure that
my threadcount is back to my start count. I just sleep again for a
few seconds in a loop and check the amount until it reaches zero.

The only catch is you have to make sure your threadpool thread doesn't
throw any exceptions that you don't handle. Otherwise, your
threadcount will not decrement and you'll "lose" threads.

Jonathan Schafer
Nov 13 '05 #7

"Jonathan Schafer" <jschafer@*NOSPAM*brierley.a.b.c.com> wrote in message
news:fe********************************@4ax.com...
On Tue, 08 Jul 2003 18:32:46 GMT, "memememe"
<[rem]casolorz[rem]@hot[rem]mail.com> wrote:

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrotein message news:Ot**************@TK2MSFTNGP11.phx.gbl...
memememe,

How are you determining that the threads are not being reused? Once
the
work item is complete, the thread should go back to the pool.

Also, the thread pool is used by other parts of the framework, and
it doesn't just run the threads whenever. It also takes other factors into consideration when deciding which items to perform work on.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"memememe" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
news:DU*********************@news1.central.cox.net ...
>
> "Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
> in message news:ux*************@tk2msftngp13.phx.gbl...
> > memememe,
> >
> > What do you mean that it is only allowed to run 25 times? Do you mean
> > that you can only have 25 concurrent activities at the same time?
> >
> > The thread pool has a limit on the number of threads that can runat
> one
> > time from it. The max is determined by the number of processors,
for each
> > processor on the machine, 25 threads are allowed in the thread pool. > >
> > Also, when your method is done, it will cause the thread pool

thread
> to
> > be sent back to the pool, to be reused later. It should not die.

This
is
> > done to improve performance and reduce the overhead from initializing new
> > threads.
> >
> > Hope this helps.
> >
> >
> > --
> > - Nicholas Paldino [.NET/C# MVP]
> > - ni**************@exisconsulting.com
> >
> >
> > "memememe" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
> > news:bo*********************@news1.central.cox.net ...
> > > We are queueing stuff on the thread pool and what we are queueing

gets
> > done
> > > pretty quick (the method returns fine) but yet its only allowed torun
> > > around 25 times, is there anything I need to do to tell the

threadpool
> > that
> > > my method is done running and the thread is to be disposed of?
> > >
> > >
> >
> >
>
>
> sorry I should have been clearer.
> We queue up a lot of work, more than 25, lets say 1k. We see the
first25
> threads get executed, then they end, once they end no more work on
the queue
> gets executed, the threads in use are 25, the available threads are 0,but
> our method ends and returns, so I am not sure what else we have to do
to > tell the thread pool to go ahead and reuse the thread.
>
>


well its a very simple program.
It queues up stuff to do on the threadpool (way more than 25) then it

doesthe stuff, I print out at the end of the method when its done processing,
and it exits fine, this happens for 25 times. There is nothing else runningon the system, its just a simple simple program, but I imagine once the
method is done running it should trhow the thread back on the queue? or do Ineed to tell the thread pool that im done running that method?

My experience has been that if a thread is not available because they
are all in use, it throws some sort of exception (which may be handled
internally) and the request just goes away. It doesn't appear to
queue them up.

Of course, I could be wrong about that but that has been my
experience.

What I do is increment a counter each time I queue a threadpool
thread. When that thread finishes, I decrement the thread count. You
can use the Interlocked class to do this.

You get 25 threads per CPU, but some of them may be used by the
framework. So, before I queue up, I check to make sure I have several
threads left. If I don't, I go to sleep for a second or two, and keep
checking in a loop until I have enough threads available. When there
are enough, I queue up another thread.

Also, if you main thread ends while threadpool threads are running,
they will be aborted, so before I leave my routine, I make sure that
my threadcount is back to my start count. I just sleep again for a
few seconds in a loop and check the amount until it reaches zero.

The only catch is you have to make sure your threadpool thread doesn't
throw any exceptions that you don't handle. Otherwise, your
threadcount will not decrement and you'll "lose" threads.

Jonathan Schafer


god I had to read the whole code a few times before I noticed what he was
doing.
He was adding more threads to the queue inside of one of the threads that
was running and wasnt letting the thread exit until the threads that it
added were done, but they werent done until they could be executed but they
couldnt be executed because the 25 thread limit was already used. Simple
change fixed it all.
Nov 13 '05 #8
Hi all

I have 2 threads, T1 and T1

Private Sub Button1_Click

Dim T1 As Thread = New System.Threading.Thread(AddressOf MyThreadTest)

Dim T2 As Thread = New Thread(AddressOf MyThreadLoad)

End sub


Public Sub MyThreadLoad()
'/// Some operation
End Sub

Public Sub MyThreadTest()
'///some operation
End Sub

In button click I need to keep T1 And T2 in a Thread Pool.

Please tell me how to do this...

Regards
Shivaraj
Jun 26 '06 #9

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

Similar topics

5
by: Dan Battagin | last post by:
Is there a known bug with the interaction between the HttpWebRequest and the ThreadPool? I current spawn several HttpWebRequest's using BeginGetResponse, and they work for a while, using worker...
5
by: Duane Pressley | last post by:
I'm looking for someone to help me make sense of the results I'm observing when using the ThreadPool class in a COM-Interop scenario. Here's the set up: 1.. A classic ASP page instantiates and calls...
6
by: Max Adams | last post by:
Threads and ThreadPool's If I use a ThreadPool how can I tell when a thead in the threadpool has exited? I don't want to set a global member variable I would much rather be able to act on an...
1
by: doudou-shen | last post by:
I will use threadpool do some work with threadpool . but I haven't any information about it . who can help me! thank a lot
13
by: orekin | last post by:
Hi There I have been programming C# for a couple of months and am trying to master Threading. I understand that ThreadPool uses background threads (see code example in MSDN page titled...
10
by: Lenn | last post by:
Hello, I have always used a certain design pattern for multithreaded Windows app; Start new worker thread from UI thread, use events to notify UI threads when something happens, update UI...
3
by: Kevin | last post by:
Using this: http://msdn2.microsoft.com/en-us/library/3dasc8as(VS.80).aspx as an example I have a question concerning the reuse of objects. In the example 10 instances of the Fibonacci class...
5
by: =?Utf-8?B?RkxEYXZlTQ==?= | last post by:
I'm developing an application that gets data from 100 sources (via telnet connections, but you can think stock quotes from a webservice if you like). I was planning on using the thread pool (25...
3
by: UltimateBanoffee | last post by:
Hi, I'm using asp.net 2.0 and I have an understanding issue here! I don't quite understand when the available threads in the ThreadPool are ever used. The application I have running doesn't use...
7
by: =?Utf-8?B?cmJEZXZlbG9wZXI=?= | last post by:
The following is from a simple Windows application in VS2005, which has button1 and textbox1 dragged onto a form. In StartThreads(), I call ThreadPool.QueueUserWorkItem(), then call WaitOne()....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.