473,406 Members | 2,208 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,406 software developers and data experts.

Custom Thread Pool in c#

Hi,
I am working on an application (developed using c#2.0) which needs to do a
big job and when you start the job in a single thread it takes long time to
complete. So, we want to break the job and run in multiple threads. I heard
about .Net Thread pool class but it has some limitations like we can't have
more than 25 threads in it and read some articles which explain the problems
with the Standard thread pool in case any of thread throws an exception and
UI problems.
Many people suggested writing custom Thread pool to solve my problem. But I
am not good at threading and I wonder whether there is any Custom thread
pool which runs robust and gains performance with multi core processors.
Basically, in my application I need to have ability to cancel any of thread
in the thread pool. Can anyone suggest me links/source code for a customized
thread pool?

Thanks in advance.

Nov 12 '07 #1
3 4024
On 2007-11-11 20:50:38 -0800, "Venkat" <st******@palantirsolutions.comsaid:
Hi,
I am working on an application (developed using c#2.0) which needs to
do a big job and when you start the job in a single thread it takes
long time to complete. So, we want to break the job and run in multiple
threads. I heard about .Net Thread pool class but it has some
limitations like we can't have more than 25 threads in it and read some
articles which explain the problems with the Standard thread pool in
case any of thread throws an exception and UI problems.
Many people suggested writing custom Thread pool to solve my problem.
But I am not good at threading and I wonder whether there is any Custom
thread pool which runs robust and gains performance with multi core
processors. Basically, in my application I need to have ability to
cancel any of thread in the thread pool. Can anyone suggest me
links/source code for a customized thread pool?
IMHO, you answered the question when you wrote "I am not good at
threading". If that's true, you should try as hard as possible to
stick with the built-in implementations.

You should be aware that for CPU-bound tasks, having more threads
running than you have CPU cores is only going to _reduce_ performance.
Even for i/o-bound tasks, there will be a point of diminishing returns.
I really doubt that you actually need more than 25 active threads, and
if your task is CPU-bound then even running as many as 25 threads is
going to be counter-productive (unless you've got yourself a 32-core
system :) ).

You're not very specific about what "problems with the Standard thread
pool" concern you, but with respect to the things you do mention:

* Can't have more than 25 threads. As I mentioned above, that's
not likely to be an actual problem.

* Threads throwing an exception. If you care about detecting
exceptions, it should be simple enough to catch them in your worker
thread entry point and deal with them there.

* UI problems. Assuming this is in regards to the prohibition
against cross-thread access to GUI components, you're going to run into
this issue no matter how you implement your threading. It's a
threading issue, not something specific to the ThreadPool class.

* Canceling individual threads. As with the exceptions, this is
something you should handle within the worker thread code, and you
would handle it the same whether you use ThreadPool or your own custom
implementation.

Finally, consider that if and when you run into problems using a thread
pool implementation, you will have a lot more success receiving help in
this newsgroup if you're using an implementation others are familiar
with. In other words, the built-in .NET implementation rather than
some custom implementation (whether yours or someone else's).

Pete

Nov 12 '07 #2
With regards to cancelling... this is always much better if done
gracefully (perhaps via a flag on each item) than forcefully. If you
can design your code to support this it would be much better. A
(synchronised) "cancelling" bool would suffice (similar to the
BackgroundWorker approach).

At the core, a custom thread-pool is just a worker thread (or threads)
and a synchronised delegate queue (or similar). Jon Skeet has a usable
sample here:
http://www.pobox.com/~skeet/csharp/miscutil/
It should do much of what you want, or provide a guide for writing
your own.

Marc

Nov 12 '07 #3
(oops; weekend over; I'll revert to "Marc", then...)

Nov 12 '07 #4

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

Similar topics

3
by: David Sworder | last post by:
This message was already cross-posted to C# and ADO.NET, but I forgot to post to this "general" group... sorry about that. It just occured to me after my first post that the "general" group readers...
0
by: Santa | last post by:
I am using Fritz Onion's "Asynchronous Pages" approach as mentioned in the article http://msdn.microsoft.com/msdnmag/issues/03/06/Threading/default.aspx to increase the performance of my ASPX...
7
by: David Sworder | last post by:
Hi, I'm developing an application that will support several thousand simultaneous connections on the server-side. I'm trying to maximize throughput. The client (WinForms) and server communicate...
5
by: Kieran Benton | last post by:
Hello, I'm currently in the tail end process of developing a high scalability server for my employer. Essentially it receives short socket based connections with an ASCII message, parses that...
1
by: buzz | last post by:
I am evaluating Mike Woodring's custom thread pool classes (Developmentor) for use with an ASP.NET project that will be implementing pages derived from IHttpAsyncHandler. (Recommended by the...
0
by: buzz | last post by:
I am new to ASP.NET, so perhaps this is problem will yield a simple answer. I am building an ASP.NET application using asynchronous handlers (IHttpAsyncHandler). In doing so, it was recommended...
5
by: admin | last post by:
ok This is my main. Pretty much it goes through each category and starts up 4 worker threads that then ask for groups to gether from. My problem is that when the thread gets done it keeps the...
0
by: roni schuetz | last post by:
since a few day's i'm running around the problem that I stocked with a change i need to do. hopefully somebody here can give me a tipp which will be usefull to solve my problem. I'm using a...
34
by: Creativ | last post by:
Why does Thread class not support IDisposable? It's creating quite some problem. Namely, it can exhaust the resource and you have not control over it.
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: 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...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.