C# - StateObject 类 - 位置
希望这应该是一个简单的问题。
我正在尝试从 http://msdn.microsoft 了解 Socket.BeginAccept 方法.com/en-us/library/bysfec7w.aspx
创建AcceptReceiveCallback方法时,需要调用StateObject类的实例,但Visual Studio上的intellisense无法识别这和代码无法编译。
我正在使用系统参考以及其他几个参考。
谢谢
This should hopefully be a simple one.
I am trying to learn about the Socket.BeginAccept Method from http://msdn.microsoft.com/en-us/library/bysfec7w.aspx
When creating the AcceptReceiveCallback method, you need to call an instance of the StateObject class, but intellisense on Visual Studio doesn't recognise this and the code doesn't compile.
I am using the System reference as well as several others.
Thankyou
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,您不需要传递 StateObject。看来该页面上的示例是不完整的,因为 StateObject 未定义。
您可以传递任何对象,甚至可以传递 null。 BeginAccept 方法并不关心。它所做的只是将该参数的值传递给 EndAccept 方法,您可以在其中从 asyncResult 的 AsyncState 属性中提取该值,您可以通过 EndAccept 方法访问该属性。
这允许您从 BeginAccept 方法传输 EndAccept 方法中可能需要的任何信息。
No, you don't need to pass a StateObject. It seems, that the example on that page is icomplete, because the StateObject is not defined.
You can pass any object or even null. The BeginAccept method does not care. All it does is pass the value of that parameter to EndAccept method, where you can extract it from the AsyncState property of the asyncResult you can access from the EndAccept method.
This allows you to transport any information you might need in the EndAccept method from the BeginAccept method.