Hi All,
Can anyone guide me when asynchronous method calls will be
benificial? Are there any
disadvantages of using asynchronous calls?
Thanks,
GVN 11 7254
GVN,
Let's make it simple: Say you have an app that needs to get rss feeds from
1000 sites once every hour. You can serialize it by having one thread go
through all 1000 requests one at a time, or you can do it asynchronously on a
threadpool with say 30 threads, in which case you will have 30 requests going
simultaneously and as soon as a thread has finished it will pick up a new
request. This may not turn out to be exactly 30 times faster than the first
case, but I think you get the idea.
Disadvantages? You have to understand how to do it correctly, and that takes
some study.
Peter
--
Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
"GVN" wrote:
Hi All,
Can anyone guide me when asynchronous method calls will be
benificial? Are there any
disadvantages of using asynchronous calls?
Thanks,
GVN
Hello, GVN!
G Can anyone guide me when asynchronous method calls will be
Gbenificial?
Its up to app design. Async method calls are used when the caller
knows that operation will take a while, so she doesn't wait for method to complete
and instead can do some more usefull job ( render UI etc ).
Good example is network I/O. If you have GUI application it will not be good if UI
freezes every time you're receiving or sending data, right?
GAre there any disadvantages of using asynchronous calls?
Usually making synchronous call is faster that async one.
This statement is valid only of method execution time is relatively small...
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
On 19 Aug 2006 05:02:25 -0700, "GVN" <mu***********@hotmail.com>
wrote:
>Hi All,
Can anyone guide me when asynchronous method calls will be benificial? Are there any
disadvantages of using asynchronous calls?
Thanks,
GVN
The BackgroundWorker class makes implementing asynch methods a breeze.
Take a look at the page below it gives a decent explanation of why you
would use asynch calls and how to use the BackgroundWorker class. http://msdn2.microsoft.com/en-us/lib...undworker.aspx
cheers
Steve
"GVN" <mu***********@hotmail.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
Hi All,
Can anyone guide me when asynchronous method calls will be
benificial? Are there any
disadvantages of using asynchronous calls?
There have been some replies that confuse multithreading with asynchronous
method calls. The two aren't the same. Threadpools and backgroundworker
threads are great but, they don't solve the same problems that async method
calls can solve.
Another reply gave an example of checking 1000 RSS feeds with a pool of 30
threads. The asynchronous approach would be to issue 1000 BeginRead() so
you have 1000 outstanding async calls then, as the reads complete, the
AsyncCallback method is called.
If you were writing a CHAT server, you could create a new thread for each
client but, that wouldn't scale very far. With an async approach, you would
call BeginRead() for each client then, when the read completes, the
AsyncCallback would call BeginWrite() for each client that the incoming
message should be directed to and then call BeginRead() again to replace the
read that just completed. This would scale to thousands of clients with
just a few threads.
John.. I don't completely understand your point since from what I see
async
method calls to COM and BeginInvoke in C# are both implemented
internally
using threadpools.
Regards,
Jeff
>Threadpools and backgroundworker
threads are great but, they don't solve the same problems that async
method
calls can solve.<
*** Sent via Developersdex http://www.developersdex.com ***
On Sat, 19 Aug 2006 13:05:34 -0400, "John Vottero"
<JV******@mvpsi.comwrote:
>"GVN" <mu***********@hotmail.comwrote in message news:11**********************@m79g2000cwm.googleg roups.com...
>Hi All,
Can anyone guide me when asynchronous method calls will be benificial? Are there any
disadvantages of using asynchronous calls? There have been some replies that confuse multithreading with asynchronous method calls. The two aren't the same. Threadpools and backgroundworker threads are great but, they don't solve the same problems that async method calls can solve.
Another reply gave an example of checking 1000 RSS feeds with a pool of 30 threads. The asynchronous approach would be to issue 1000 BeginRead() so you have 1000 outstanding async calls then, as the reads complete, the AsyncCallback method is called.
If you were writing a CHAT server, you could create a new thread for each client but, that wouldn't scale very far. With an async approach, you would call BeginRead() for each client then, when the read completes, the AsyncCallback would call BeginWrite() for each client that the incoming message should be directed to and then call BeginRead() again to replace the read that just completed. This would scale to thousands of clients with just a few threads.
Hi John
Granted asynch calls and multithreading aren't the same thing.
However, it is often desirable to execute an asynch calls on it's own
thread, as is the case when trying to avoid an unresponsive UI in a
windows app for instance, the two methods can be used together. Or so
I thought.
If I'm mistaken I'd appreciate your advice on how best to approach
this. Assuming I'm not looking to scale to thousands of users, just a
single user using the app, how should I ensure the app remains
responsive whilst waiting for a request, to a webservice for instance,
to complete? For me the BackgroundWorker solves this problem and with
less effort than has previously been the case.
There are many ways to approach a problem and I'd be interested to
know how others might solve problems like this.
Cheers
Steve
John Vottero <JV******@mvpsi.comwrote:
There have been some replies that confuse multithreading with asynchronous
method calls. The two aren't the same. Threadpools and backgroundworker
threads are great but, they don't solve the same problems that async method
calls can solve.
To be clear here - they aren't *always* the same. They sometimes are.
Basically when you use asynchronous *IO* you use IO completion ports
rather than a single thread per connection.
However, other types of asynchronous call (SomeDelegate.BeginInvoke,
Control.BeginInvoke etc) *are* just multithreading using the
threadpool.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
"Jeff Louie" <an*******@devdex.comwrote in message
news:ed**************@TK2MSFTNGP06.phx.gbl...
John.. I don't completely understand your point since from what I see
async
method calls to COM and BeginInvoke in C# are both implemented
internally
using threadpools.
The only point I was trying to make is that there's a difference between
multithreaded programming (which is inherently asynchronous) and
asynchronous method calls. It's important to understand the difference
between calling ThreadPool.QueueUserWorkItem and BeginRead. I'm not saying
that one is better than the other, they're just different.
"steve.falzon@ noonbay.co.uk" <nospampleasewrote in message
news:9o********************************@4ax.com...
On Sat, 19 Aug 2006 13:05:34 -0400, "John Vottero"
<JV******@mvpsi.comwrote:
>>"GVN" <mu***********@hotmail.comwrote in message news:11**********************@m79g2000cwm.google groups.com...
>>Hi All,
Can anyone guide me when asynchronous method calls will be benificial? Are there any
disadvantages of using asynchronous calls? There have been some replies that confuse multithreading with asynchronous method calls. The two aren't the same. Threadpools and backgroundworker threads are great but, they don't solve the same problems that async method calls can solve.
Another reply gave an example of checking 1000 RSS feeds with a pool of 30 threads. The asynchronous approach would be to issue 1000 BeginRead() so you have 1000 outstanding async calls then, as the reads complete, the AsyncCallback method is called.
If you were writing a CHAT server, you could create a new thread for each client but, that wouldn't scale very far. With an async approach, you would call BeginRead() for each client then, when the read completes, the AsyncCallback would call BeginWrite() for each client that the incoming message should be directed to and then call BeginRead() again to replace the read that just completed. This would scale to thousands of clients with just a few threads.
Hi John
Granted asynch calls and multithreading aren't the same thing.
However, it is often desirable to execute an asynch calls on it's own
thread, as is the case when trying to avoid an unresponsive UI in a
windows app for instance, the two methods can be used together. Or so
I thought.
I didn't mean to imply that asynch calls were better than multithreading, I
just wanted to point out the difference.
>
If I'm mistaken I'd appreciate your advice on how best to approach
this. Assuming I'm not looking to scale to thousands of users, just a
single user using the app, how should I ensure the app remains
responsive whilst waiting for a request, to a webservice for instance,
to complete? For me the BackgroundWorker solves this problem and with
less effort than has previously been the case.
I use BackgroundWorker threads all the time, I think they're great. But, if
you might have hundreds of outstanding webservice calls, you probably don't
want to have a thread for each one of them.
>
There are many ways to approach a problem and I'd be interested to
know how others might solve problems like this.
Cheers
Steve
"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP***********************@msnews.microsoft.co m...
| John Vottero <JV******@mvpsi.comwrote:
| There have been some replies that confuse multithreading with
asynchronous
| method calls. The two aren't the same. Threadpools and
backgroundworker
| threads are great but, they don't solve the same problems that async
method
| calls can solve.
|
| To be clear here - they aren't *always* the same. They sometimes are.
| Basically when you use asynchronous *IO* you use IO completion ports
| rather than a single thread per connection.
|
| However, other types of asynchronous call (SomeDelegate.BeginInvoke,
| Control.BeginInvoke etc) *are* just multithreading using the
| threadpool.
What makes you think that Control.BeginInvoke uses the threadpool?, it
simply queues a delegate and posts a message to the windows message queue
associated with the Control's HWND, the threadpool is not used here.
Willy.
Willy Denoyette [MVP] <wi*************@telenet.bewrote:
What makes you think that Control.BeginInvoke uses the threadpool?, it
simply queues a delegate and posts a message to the windows message queue
associated with the Control's HWND, the threadpool is not used here.
Sorry, yes - don't know what I was thinking of there. I'm pretty sure
about Delegate.BeginInvoke though :)
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Bryan |
last post by:
I have a multi-threaded C# console application that uses WMI
(System.Management namespace) to make RPC calls to several servers (600+ )
and returns ScheduledJobs. The section of my code that...
|
by: Oscar Thornell |
last post by:
Hi,
I am thinking about doing all my logging asynchronously using a delegate.
The main resaon for this would be performance and responsiveness of the
application (an ASP.NET app).
//Exampel...
|
by: Jared |
last post by:
I'm using the first code sample below to play WAV files stored as
embedded resources. For some reason I *occasionally* get scratching
and crackling. I'm using a couple WAVs that ship with...
|
by: =?Utf-8?B?dGhlamFtaWU=?= |
last post by:
In the sample VB application for Filestream.BeginWrite Method, there is no
NEW implementation on the AsyncCallBack Object and sample below calls for
declaring both the "State" object and the...
|
by: Mohamed Mansour |
last post by:
Hey there, this will be somewhat a long post, but any response is
appreciated!
I have done many PInvoke in the past from C++ to C#, but I did PInvoke
within C# not C++/CLI.
Can someone explain...
|
by: StefanPienaar |
last post by:
Hi
I was recently given the task of converting an Asp.net 1.1 portal to Asp.net 3.5.
The problem is it includes a webservice and a lot of the methods are called asynchronously. Now in .net 1.1...
|
by: Pixel.to.life |
last post by:
Dear All,
Here is a problem I am facing (it might be too simple, but then I
admit I am not a Guru:-)
I have a main thread, in managed C++, that deals with displaying a
form and some controls....
|
by: James |
last post by:
Hello,
I am new to C# programming and I am using delegates for the event-
driven application and found them very useful.
Are there any applications where delegates may not be useful ? Can...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
| |