473,385 Members | 1,409 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.

Use Thread or ThreadPool

Hi All,

I'm currently developping something where I need to use threads.
Here's the basic scenario. I have a WebService requests which need to
launch a few threads and wait for them to complete before returning a
responses. Bascically, each thread will make a request to our old C++
server and wait for the answer before completing. Also, the WebService
request thread will wait until all the server requests thread are
completed ( or timed-out) before returning a response.
>From what I've gathered, I could either use the Thread class or the
ThreadPool class to realize this. To me, it seems the ThreadPool would
be easier since I could simply tell it to start all my request and
wait for them to complete. Still, is there anything that I'm missing
here and that might make it not a good idea to use threadpool. I'm new
to C# threads and want to make sure I'm not overlooking something.

Thank you
Simon

P.S. I know that threadpool is limited to 25 threads by default and I
don't think this will create problems with what I want to do.

Oct 15 '07 #1
4 2648
Simon,

Are you looking to hold up a currently executing thread, or are you just
want to receive notification when all of the calls are complete? IIRC, the
proxies to the web services should allow you to make calls asynchronously,
so you could easily get the IAsyncResult from the async call and then wait
on all the handles that the IAsyncResult implementations expose.

If you want to be notified when all the calls are done, then you are
going to have to create a data structure which will be notified by each of
the callbacks when you make the asynchronous calls, which should then fire
it's own event when the last callback is specified.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Simon" <dr**@step.polymtl.cawrote in message
news:11**********************@i13g2000prf.googlegr oups.com...
Hi All,

I'm currently developping something where I need to use threads.
Here's the basic scenario. I have a WebService requests which need to
launch a few threads and wait for them to complete before returning a
responses. Bascically, each thread will make a request to our old C++
server and wait for the answer before completing. Also, the WebService
request thread will wait until all the server requests thread are
completed ( or timed-out) before returning a response.
>>From what I've gathered, I could either use the Thread class or the
ThreadPool class to realize this. To me, it seems the ThreadPool would
be easier since I could simply tell it to start all my request and
wait for them to complete. Still, is there anything that I'm missing
here and that might make it not a good idea to use threadpool. I'm new
to C# threads and want to make sure I'm not overlooking something.

Thank you
Simon

P.S. I know that threadpool is limited to 25 threads by default and I
don't think this will create problems with what I want to do.

Oct 15 '07 #2
Hi Nicholas,

I want to hold up the currently executing thread until all the others
threads have completed or timed-out. I'm just doing a demo of a new
features and want the implementation to be as easy as possible for
now. I might use asynchronous call later if needed, but for now, I'll
hold up the current thread.

My main worry here is with the WebService. I'm not sure how the
WebService works in the background to dispatch it's request, but my
guess is that it must itself use a threadpool. If I use a threadpool
in the code handling a WebService request, would I be queuing items in
the same threadpool as the WebService?

Simon

Oct 15 '07 #3
On Oct 15, 4:19 pm, Simon <d...@step.polymtl.cawrote:
I want to hold up the currently executing thread until all the others
threads have completed or timed-out.
That sounds like a simple call to Thread.Join with a timeout.

<snip>
My main worry here is with the WebService. I'm not sure how the
WebService works in the background to dispatch it's request, but my
guess is that it must itself use a threadpool. If I use a threadpool
in the code handling a WebService request, would I be queuing items in
the same threadpool as the WebService?
Yes, if you use the system threadpool. There are various third-party
threadpools available - I have one at http://pobox.com/~skeet/csharp/miscutil,
but it doesn't necessarily do everything you want or need.

Jon

Oct 15 '07 #4
Simon,

In this case, you don't have to use the threadpool directly, as the
proxies which you are going to use are going to use the threadpool to make
the calls to the web service.

Yes, if you are handling other tasks in the thread pool, then the web
request is going to use the same thread pool.

If you want to hold up the currently executing thread, make
asyncnrhonous calls, getting the IAsyncResult implementations, and then call
the WaitHandle property, placing the result in an array of WaitHandles.
Then pass that array to the static WaitAll method on the WaitHandle class,
and the call will return when all of the calls are complete.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Simon" <dr**@step.polymtl.cawrote in message
news:11*********************@q5g2000prf.googlegrou ps.com...
Hi Nicholas,

I want to hold up the currently executing thread until all the others
threads have completed or timed-out. I'm just doing a demo of a new
features and want the implementation to be as easy as possible for
now. I might use asynchronous call later if needed, but for now, I'll
hold up the current thread.

My main worry here is with the WebService. I'm not sure how the
WebService works in the background to dispatch it's request, but my
guess is that it must itself use a threadpool. If I use a threadpool
in the code handling a WebService request, would I be queuing items in
the same threadpool as the WebService?

Simon

Oct 15 '07 #5

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

Similar topics

31
by: AlexeiOst | last post by:
Everywhere in documentation there are recommendations to use threads from thread pooling for relatively short tasks. As I understand, fetching a page or multiple pages (sometimes up to 50 but not...
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...
9
by: Drew | last post by:
I keep seeing this when I run my program in Visual Studio: The thread '<No Name>' (0x894) has exited with code 0 (0x0). What does this mean exactly? It doesn't seem to be causing a problem. ...
4
by: Matthew Groch | last post by:
Hi all, I've got a server that handles a relatively high number of concurrent transactions (on the magnitude of 1000's per second). Client applications establish socket connections with the...
2
by: objectref | last post by:
hi to all folks, i want to create the following senario: i have a T1 (Thread 1) that acts like http server that receives incoming requests. From that T1, i want to spawn from T1 to Tn thread...
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...
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...
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.
7
by: Curious | last post by:
On Jun 10, 3:32 am, <s...@dailycoding.comwrote: Thanks! I'll use thread pool.
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: 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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.