使用C#异步使用调用方法的缺点 [英] Disadvantages of using calling methods asynchronously using C#

查看:316
本文介绍了使用C#异步使用调用方法的缺点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


任何人都可以在异步方法调用时指导我

benificial?使用异步调用有什么好处吗?

谢谢,


GVN

解决方案

GVN,

让我们简单一点:假设您有一个应用程序需要从

每小时1000个站点。你可以通过让一个线程一次一个地通过所有1000个请求获得
来序列化它,或者你可以在一个

线程池上异步地执行它,比如30个线程,其中如果你有30个请求同时进行

,一旦线程完成,它将获得一个新的

请求。这可能不会比第一个

的情况快30倍,但我认为你明白了。


缺点?你必须明白如何正确地做到这一点,并且需要学习



彼得


-

联合创始人,Eggheadcafe.com开发者门户网站:
http:// www .eggheadcafe.com

UnBlog:
http: //petesbloggerama.blogspot.com


" GVN"写道:


大家好,


任何人都可以在异步方法调用时指导我

有益吗?使用异步调用有什么好处吗?


谢谢,


GVN


你好,GVN!


G任何人都可以在异步方法调用时指导我/>
Gbenificial?


由应用程序设计决定。当调用者

知道操作需要一段时间时,会使用异步方法调用,因此她不等待方法完成

而是可以做一些更有用的操作工作(渲染UI等)。


很好的例子是网络I / O.如果您有GUI应用程序,那么每次接收或发送数据时,如果UI

冻结,那就不好了,对吧?


是否有使用异步调用的任何缺点?

通常进行同步调用比异步调用更快。

此声明仅对方法执行时间相对较小有效...


-

问候,Vadym Stetsyak

www: http://vadmyst.blogspot.com


2006年8月19日05:02:25 -0700,GVN < mu *********** @ hotmail.com>

写道:


>大家好,


任何人都可以指导我异步方法调用是否有益?使用异步调用有什么缺点吗?

谢谢,

GVN



BackgroundWorker类使得实现异步方法变得轻而易举。

看一下下面的页面,它给出了为什么你会使用异步调用以及如何使用异步调用的合理解释使用BackgroundWorker类。
http ://msdn2.microsoft.com/en-us/lib...undworker.aspx

欢呼


史蒂夫


Hi All,

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

disadvantages of using asynchronous calls?
Thanks,

GVN

解决方案

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


这篇关于使用C#异步使用调用方法的缺点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆