473,785 Members | 2,910 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ThreadPool or BeginInvoke()?

I'm writing an application invoking asynchon methods.

I envision using the .NET thread pool since it matches
well my needs.

There is (at least) 2 methods to do that:
using ThreadPool class directely or using the BeginInvoke
() of a delegate.

Does anybody knows any advantages from one method to
another?

thank you

Nov 16 '05 #1
2 3645
fred <an*******@disc ussions.microso ft.com> wrote:
I'm writing an application invoking asynchon methods.

I envision using the .NET thread pool since it matches
well my needs.

There is (at least) 2 methods to do that:
using ThreadPool class directely or using the BeginInvoke
() of a delegate.

Does anybody knows any advantages from one method to
another?


See http://www.pobox.com/~skeet/csharp/t...readpool.shtml for
detailed comments, but:

o QueueUserWorkIt em only allows a single parameter, of type object
o QueueUserWorkIt em doesn't allow you to specify a callback
o QueueUserWorkIt em doesn't require EndInvoke or anything similar

(The reverse is true for BeginInvoke in each case.)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
thank you.

I did not see that
QueueUserWorkIt em doesn't allow you to specify a callback

this is enough to convinct me for using BeginInvoke()

thank you
-----Original Message-----
fred <an*******@disc ussions.microso ft.com> wrote:
I'm writing an application invoking asynchon methods.

I envision using the .NET thread pool since it matches
well my needs.

There is (at least) 2 methods to do that:
using ThreadPool class directely or using the BeginInvoke () of a delegate.

Does anybody knows any advantages from one method to
another?
See

http://www.pobox.com/~skeet/csharp/t...hreadpool.shtm
l fordetailed comments, but:

o QueueUserWorkIt em only allows a single parameter, of type objecto QueueUserWorkIt em doesn't allow you to specify a callbacko QueueUserWorkIt em doesn't require EndInvoke or anything similar
(The reverse is true for BeginInvoke in each case.)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.

Nov 16 '05 #3

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

Similar topics

11
3373
by: AA | last post by:
Why microsoft make so hard to change the max Pool Size?? I really need to change it to 50, because I'm using delegates with BeginInvoke and I saw that they (delegates) use the ThreadPool, but I saw too that is very complicate to change the ThreadPool size and if I want, I need to use unmanage resources http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=201 If I use unmanage resources my application will not be portable...
2
3973
by: Mark Hoffman | last post by:
All, My application spawns a worker process by calling BeginInvoke with an asynchronous callback method. This callback method is responsible for calling EndInvoke. No problems there; pretty much straight out of MSDN. My question is what happens when my worker thread raises an exception? I can easily catch the exception, but I've noticed that unless my async callback runs and EndInvoke gets called, then the worker thread never gets...
3
5230
by: SSonnenwald | last post by:
I have created a piece of code that uses a ThreadPool class and the QueueUserWorkItem method to add items to the the ThreadPool. What would seem to be simple I just can not figure out how to tell if all of the threads in the threadpool that I queued have completed. Does anyone have a way???? Any help would be appreciated. Thanks, Scott
6
2759
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 event Also (failing this ThreadPool issue) is it possible to create an array of Worker Threads, can anyone illustrate with code please Thanks
7
6082
by: Novice | last post by:
I come from the land of Java and C++** where it is relatively easy to create a pool of threads, send them off to a task, then call the join method and await all of their completion. However, I cannot for the life of me figure out how to get this relatively simple concept working in .net - specifically C#. I posted some code earlier where I was using ThreadPool.QueueUserWorkItem - I couldn't figure out how to get my code to wait for the...
13
2522
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 'ThreadPool Class ') .... however I would like to ensure that all my ThreadPool threads have completed before I exit my Main function.
10
8781
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 questions; 1. what's the difference? 2. Any performance benefits?
5
6593
by: FP | last post by:
Hi, i'm currently developing a class to communicate with a serial device,using the SerialPort component. Basically,the main application will interact with this class through its method "Call",the class itself will handle all the details of a call (AT commands included). My problem is that i dont want the application to hang while i'm interacting with the modem,so i have started to learn about threading. Many people have suggested me to...
7
7205
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(). My expectation is that I would see the text generated in WasteTime() before seeing the "Hey" printout that comes after WaitOne(). Instead, I'm seeing the "Hey" as the first thing to print out in the text box. Any thoughts on why WaitOne() isn't...
0
9645
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8973
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4053
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
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.