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

ThreadPool problem

Hi,
I have a .NET class which uses the .NET threadpool (using QueueUserWorkItem)
to create about 8 threads, which do some work while the parent thread waits
for them all to complete, which works fine when referenced from a normal EXE.

When I reference this DLL in a webservice however, the threads seem to be
created one by one in order, rather than at the same time - it is as if there
is only one available thread in the ThreadPool and the rest are being queued.
I can see this as I have code that writes the execution order to the event
log. In the version referenced from the EXE the order they return is in
keeping with what I would expect based on how long each takes i.e., the
fastest returns first, the slowest last. From the webservice, they appear in
the other they are created. I changed the first thread to sleep for 10
seconds, and it in the webservice it still finished first. The same code from
the EXE and it finished last, as you would expect.

Any ideas on why this is happening as the performance loss when I use this
in the webservice is massive. I read that ASP.Net (or IIS) also uses the
ThreadPool, but the system isn't even loaded. I called GetAvailableThreads()
which returned 50.

Thanks,
DAve
Nov 19 '05 #1
3 1329

"Dave" <Da**@discussions.microsoft.com> wrote in message
news:E4**********************************@microsof t.com...
Hi,
I have a .NET class which uses the .NET threadpool (using
QueueUserWorkItem)
to create about 8 threads, which do some work while the parent thread
waits
for them all to complete, which works fine when referenced from a normal
EXE.

When I reference this DLL in a webservice however, the threads seem to be
created one by one in order, rather than at the same time - it is as if
there
is only one available thread in the ThreadPool and the rest are being
queued.
I can see this as I have code that writes the execution order to the event
log. In the version referenced from the EXE the order they return is in
keeping with what I would expect based on how long each takes i.e., the
fastest returns first, the slowest last. From the webservice, they appear
in
the other they are created. I changed the first thread to sleep for 10
seconds, and it in the webservice it still finished first. The same code
from
the EXE and it finished last, as you would expect.

Any ideas on why this is happening as the performance loss when I use this
in the webservice is massive. I read that ASP.Net (or IIS) also uses the
ThreadPool, but the system isn't even loaded. I called
GetAvailableThreads()
which returned 50.


I'm not sure what's exactly happening to you, but as you mentioned ASP.NET
uses the built-in threadpool. The consequence of this is that you aren't
supposed to use it in ASP.NET applications. Rewrite your code to use a
custom thread pool or to spawn threads and you will fix a latent bug in your
application, and your problem will probably go away.

David
Nov 19 '05 #2
Hi David,
Thanks for your reply. Interestingly, the problem only occurs on IIS6. On my
local machine which runs IIS 5.1, the problem does not happen, only when I
deploy to our Windows Server 2003 IIS6 box. It seems really odd to me that I
can't create more than one thread from the ThreadPool.

Thanks,
Dave

"David Browne" wrote:

"Dave" <Da**@discussions.microsoft.com> wrote in message
news:E4**********************************@microsof t.com...
Hi,
I have a .NET class which uses the .NET threadpool (using
QueueUserWorkItem)
to create about 8 threads, which do some work while the parent thread
waits
for them all to complete, which works fine when referenced from a normal
EXE.

When I reference this DLL in a webservice however, the threads seem to be
created one by one in order, rather than at the same time - it is as if
there
is only one available thread in the ThreadPool and the rest are being
queued.
I can see this as I have code that writes the execution order to the event
log. In the version referenced from the EXE the order they return is in
keeping with what I would expect based on how long each takes i.e., the
fastest returns first, the slowest last. From the webservice, they appear
in
the other they are created. I changed the first thread to sleep for 10
seconds, and it in the webservice it still finished first. The same code
from
the EXE and it finished last, as you would expect.

Any ideas on why this is happening as the performance loss when I use this
in the webservice is massive. I read that ASP.Net (or IIS) also uses the
ThreadPool, but the system isn't even loaded. I called
GetAvailableThreads()
which returned 50.


I'm not sure what's exactly happening to you, but as you mentioned ASP.NET
uses the built-in threadpool. The consequence of this is that you aren't
supposed to use it in ASP.NET applications. Rewrite your code to use a
custom thread pool or to spawn threads and you will fix a latent bug in your
application, and your problem will probably go away.

David

Nov 19 '05 #3

"Dave" <Da**@discussions.microsoft.com> wrote in message
news:04**********************************@microsof t.com...
Hi David,
Thanks for your reply. Interestingly, the problem only occurs on IIS6. On
my
local machine which runs IIS 5.1, the problem does not happen, only when I
deploy to our Windows Server 2003 IIS6 box. It seems really odd to me that
I
can't create more than one thread from the ThreadPool.


You can't create any threads from the thread pool. The thread pool creates
its own threads. When using the thread pool, you just add work to the
thread pool, and sometime later an availiable thread performs the work. Are
you sure you're coding this correctly?

David
Nov 19 '05 #4

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...
4
by: David Levine | last post by:
Jon, I've taken a look at it and these comments are based on a code-inspection but I did not verify the correctness if its operation by using it in a sample. The ctor for CustomThreadPool...
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...
16
by: NOtcarvinSPAM | last post by:
It occurs to me that if I have a work object that gets executed via QueueUserWorkItem AND the work proc accesses only that object's instance data I STILL may have to lock because the object...
4
by: Jonathan Howard | last post by:
I am trying to create a page where multiple requests are made to a single webservice. This webservice takes a fair amount of time to process the requests so rather than making the calls one at a...
1
by: Sam | last post by:
Hi All, I'm trying to write a simple multi-threaded windows service application using ThreadPool and I'm running into the same problem as described by MS article:...
7
by: Sin Jeong-hun | last post by:
Hi. I'm writing a Client/Multi-threaded Server program on Windows Vista. It worked fine on Windows Vista, but when the server ran on Windows XP, I/O operation has been aborted because of either...
6
by: Ricardo Vazquez | last post by:
Hello everybody, I'm programming a TCP server. During the stress tests I noticed that maybe my socket-receiving thread became deaf after an hour of heavy stress. I think that the reason could...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.