在WebSocketContext中正确处理WebSocket(Proper disposal of WebSocket in a WebSocketContext)

编程入门 行业动态 更新时间:2024-10-12 14:24:26
在WebSocketContext中正确处理WebSocket(Proper disposal of WebSocket in a WebSocketContext)

在ASP.NET中,当您提供给HttpContext.AcceptWebSocketRequest的处理程序获取AspNetWebSocketContext时 ,是否应该在完成后处理上下文的WebSocket ? 或者,在您调用WebSocket.CloseAsync之后,Web套接字是否会自动处理?

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?

最满意答案

您不应该丢弃Web套接字。 实际上你不能。 AspNetWebSocket.Dispose始终抛出NotSupportedException 。 MSDN文档的摘要和例外部分不正确。 幸运的是,备注部分很有帮助:

ASP.NET自动调用AspNetWebSocket对象上的Dispose方法,以释放代码完成执行后剩余的所有资源。

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 automatically calls the Dispose method on a AspNetWebSocket object to release any resources that remain after your code has finished executing.

更多推荐

本文发布于:2023-07-23 02:30:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1226460.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:正确处理   WebSocketContext   WebSocket   disposal   Proper

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!