什么是BeginConnect和ConnectAsync之间的区别? [英] What's the difference between BeginConnect and ConnectAsync?

查看:926
本文介绍了什么是BeginConnect和ConnectAsync之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是什么和 BeginConnect 之间的差异 ConnectAsync ?随后,就是 BeginDisconnect 之间的差异, DisconnectAsync

What is the difference between BeginConnect and ConnectAsync? Subsequently, what is the difference between BeginDisconnect and DisconnectAsync?

的<一个href=\"http://msdn.microsoft.com/en-us/library/bb538102%28v=vs.95%29.aspx\"><$c$c>ConnectAsync文档状态:

开始一个对远程主机连接的异步请求。

"Begins an asynchronous request for a remote host connection."

的<一个href=\"http://msdn.microsoft.com/en-us/library/tad07yt6%28v=VS.100%29.aspx\"><$c$c>BeginConnect文档同时规定:

开始一个对远程主机连接的异步请求。

"Begins an asynchronous request for a remote host connection."

无论是<一个href=\"http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.disconnectasync.aspx\"><$c$c>DisconnectAsync和<一个href=\"http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.begindisconnect.aspx\"><$c$c>BeginDisconnect也说明了同样的事情:

Both the DisconnectAsync and BeginDisconnect also state the same thing:

开始异步请求从远程终结点断开连接。

"Begins an asynchronous request to disconnect from a remote endpoint."

有什么方法,那些对,哪一个应该使用之间的区别?

What's the difference between those method pairs and which one should be used?

推荐答案

Socket.ConnectAsync提供的SocketAsyncEventArgs与通过BeginConnect提供3 PARAMS里面包含了很多更多信息的参数。我也知道,ConnectAsync后来推出比BeginConnect并解决相关的超时(不记得这个讨论的来源现在)一些问题。 preFER ConnectAsync时可能(尽管它需要分NET 2.0 SP1)。

Socket.ConnectAsync provides SocketAsyncEventArgs as a parameters which contains a lot more information compared to 3 params provided by BeginConnect. Also I know that ConnectAsync introduced later than BeginConnect and solves some issues related to timeouts (cannot remember the source of this discussion now). Prefer ConnectAsync when possible (though it requires min .NET 2.0 SP1).

有与ConnectAsync一个catch关于回调。如果这是值得关注的,下面是关于它的讨论:<一href=\"http://stackoverflow.com/questions/3954668/stack-overflow-when-using-the-system-net-sockets-socket-acceptasync-model\">Stack溢出使用System.Net.Sockets.Socket.AcceptAsync模型时和的AsyncCallback CompletedSynchronously

There is a catch with ConnectAsync about the callbacks. If this is of concern, here are the discussions about it: Stack overflow when using the System.Net.Sockets.Socket.AcceptAsync model and AsyncCallBack CompletedSynchronously

有是在Silverlight BeginConnect方法不支持(仅ConnectAsync支持),所以如果你打算开发客户端的Silverlight应用程序,可能是另一个问题。

There is no support for BeginConnect method in Silverlight (only ConnectAsync is supported) so that may be another concern if you intend to develop client side Silverlight applications.

此外,在这两种方法中使用的模式不同。这里是讨论:<一href=\"http://stackoverflow.com/questions/5202608/is-there-any-performance-difference-between-begin-and-async-for-sockets-in-net\">Is有之间的性能差异开始*和*异步套接字在.NET?

Also the patterns used in two approaches are different. Here is the discussion: Is there any performance difference between Begin* and *Async for sockets in .NET?

这篇关于什么是BeginConnect和ConnectAsync之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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