473,657 Members | 2,582 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Disadvantages of using calling methods asynchronously using C#

GVN
Hi All,

Can anyone guide me when asynchronous method calls will be
benificial? Are there any

disadvantages of using asynchronous calls?
Thanks,

GVN

Aug 19 '06 #1
11 7317
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

Aug 19 '06 #2
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
Aug 19 '06 #3
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

disadvantage s of using asynchronous calls?
Thanks,

GVN

The BackgroundWorke r 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 BackgroundWorke r class.
http://msdn2.microsoft.com/en-us/lib...undworker.aspx
cheers

Steve
Aug 19 '06 #4
"GVN" <mu***********@ hotmail.comwrot e in message
news:11******** **************@ m79g2000cwm.goo glegroups.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 backgroundworke r
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.

Aug 19 '06 #5
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 backgroundworke r
threads are great but, they don't solve the same problems that async
method
calls can solve.<

*** Sent via Developersdex http://www.developersdex.com ***
Aug 19 '06 #6
On Sat, 19 Aug 2006 13:05:34 -0400, "John Vottero"
<JV******@mvpsi .comwrote:
>"GVN" <mu***********@ hotmail.comwrot e in message
news:11******* *************** @m79g2000cwm.go oglegroups.com. ..
>Hi All,

Can anyone guide me when asynchronous method calls will be
benificial? Are there any

disadvantage s of using asynchronous calls?

There have been some replies that confuse multithreading with asynchronous
method calls. The two aren't the same. Threadpools and backgroundworke r
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
AsyncCallbac k 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
AsyncCallbac k 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 BackgroundWorke r 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
Aug 19 '06 #7
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 backgroundworke r
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.B eginInvoke,
Control.BeginIn voke etc) *are* just multithreading using the
threadpool.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 20 '06 #8
"Jeff Louie" <an*******@devd ex.comwrote in message
news:ed******** ******@TK2MSFTN GP06.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.Queu eUserWorkItem and BeginRead. I'm not saying
that one is better than the other, they're just different.

Aug 20 '06 #9
"steve.falz on@ noonbay.co.uk" <nospampleasewr ote in message
news:9o******** *************** *********@4ax.c om...
On Sat, 19 Aug 2006 13:05:34 -0400, "John Vottero"
<JV******@mvpsi .comwrote:
>>"GVN" <mu***********@ hotmail.comwrot e in message
news:11****** *************** *@m79g2000cwm.g ooglegroups.com ...
>>Hi All,

Can anyone guide me when asynchronous method calls will be
benificial? Are there any

disadvantag es of using asynchronous calls?

There have been some replies that confuse multithreading with asynchronous
method calls. The two aren't the same. Threadpools and backgroundworke r
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
AsyncCallba ck 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
AsyncCallba ck 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 BackgroundWorke r solves this problem and with
less effort than has previously been the case.
I use BackgroundWorke r 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

Aug 20 '06 #10

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

Similar topics

15
11760
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 performs the query is contained in a delegate function that I execute via a second thread. On 1 or 2 of the 600+ servers the query hangs. I've tried to use Thread.Join() coupled with a Thread.Abort() but this does not kill the thread. Based on...
3
4503
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 delegate void LogDelegate(string message); LogDelegate logger = new LogDelegate(Log.Debug); logger.DynamicInvoke("Some message..");
3
10631
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 Windows, and they play fine outside of my app. This code works, but has the random "scratching" problem: private static void PlayResource(string audioRes) { // Get the resource into a stream
0
1230
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 AsynCallBack object. I added the Imports System.IO, System.Threading, and Microsoft VisualBasic in the hopes that this would fix the issue. All the c,C# and J# calls declare the asnc... as new. Can someone get this to work? Shared Sub Main() '...
14
3776
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 more why C++/CLI would be better to PInvoke than doing the PInvoke in C#? Because, usually in C# as you already know we use DLLImport and extern
2
1729
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 the stub creates the .Begin and .End methods for you and in Asp.net 2.0 it creates the .Asyn method when you create a reference to the webservice. It seems that 3.5 does not use either of these methods and I can't find an article explaining the...
15
2664
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. I invoke another thread for some processing from this thread, so basically the main thread is waiting on the sub thread.
12
6727
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 anyone please let me know what are the disadvantages of using delegates. Thanks, James.
0
8392
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
8305
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
8825
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7324
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...
0
4302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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
2
1953
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1611
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.