473,568 Members | 2,898 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2664
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.co m

"Simon" <dr**@step.poly mtl.cawrote in message
news:11******** **************@ i13g2000prf.goo glegroups.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.poly mtl.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.co m

"Simon" <dr**@step.poly mtl.cawrote in message
news:11******** *************@q 5g2000prf.googl egroups.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
2452
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 tipical) from the Internet and doing some processing on those would be considered to be a big/long task for a thread from a pool. In our app it is...
7
2850
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 via a socket connection (no remoting, no ASP.NET). The client sends a message to the server that contains some instructions and the server responds...
9
20397
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. Thanks, Drew
4
5421
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 server. Data is sent and received over these connections using the asynchronous model. The server is currently in beta testing. Sporadically over the...
2
4699
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 jobs and beeing able to be notified when each of these threads finished it's job.
10
8759
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 controls using delegates through .BeginInvoke. I came across some code samples recently where ThreadPool class is used to start new threads. My...
7
5890
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 a thread exit or an application request exception randomly occurred at the OnReceive method (asynchronous tcp stream reading). I searched all...
34
2762
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
1626
by: Curious | last post by:
On Jun 10, 3:32 am, <s...@dailycoding.comwrote: Thanks! I'll use thread pool.
0
7693
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7916
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8117
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7660
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5498
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2101
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.