在WebSocketContext妥善处置的WebSocket的 [英] Proper disposal of WebSocket in a WebSocketContext

查看:548
本文介绍了在WebSocketContext妥善处置的WebSocket的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ASP.NET中,当处理您提供的 HttpContext.AcceptWebSocketRequest 得到一个 AspNetWebSocketContext ,你应该处置方面的的WebSocket 当你用它做?还是网络套接字得到自动处理,或许以后你叫的 WebSocket.CloseAsync

In ASP.NET, when the handler you provide to HttpContext.AcceptWebSocketRequest gets a AspNetWebSocketContext, should you dispose the context's WebSocket when you are done with it? Or does the web socket get disposed automatically, perhaps after you call WebSocket.CloseAsync?

推荐答案

您不要配置网络接口。事实上你不能。 <一href=\"http://stackoverflow.com/questions/14022120/proper-disposal-of-websocket-in-a-websocketcontext\">AspNetWebSocket.Dispose总是抛出一个引发NotSupportedException 。 MSDN文档的摘要和异常的部分是不正确的。幸运的是,注释部分是有帮助的:

You should not dispose the web socket. In fact you cannot. AspNetWebSocket.Dispose always throws a NotSupportedException. The summary and exception sections of the MSDN documentation are incorrect. Fortunately, the remarks section is helpful:

ASP.NET自动调用一个AspNetWebSocket Dispose方法
  反对释放保持你的code有之后的任何资源
  执行完成。

ASP.NET automatically calls the Dispose method on a AspNetWebSocket object to release any resources that remain after your code has finished executing.

这篇关于在WebSocketContext妥善处置的WebSocket的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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