[英]can i check a tcpclient is disposed or not in tcp ip in c#
i want create a server for tcp/ip我想为 tcp/ip 创建一个服务器
i have this code:我有这个代码:
if (myTcpClient.Available == 0)
{
}
when client has disposed i receive this error:当客户处理我收到此错误:
System.Object Disposed Exception: 'Cannot access a disposed object.
can i check client is disposed or not?我可以检查客户是否已处置? thank you can i check client is disposed or not?谢谢 我可以检查客户是否已处置? thank you can i check client is disposed or not?谢谢 我可以检查客户是否已处置? thank you can i check client is disposed or not?谢谢 我可以检查客户是否已处置? thank you can i check client is disposed or not?谢谢 我可以检查客户是否已处置? thank you can i check client is disposed or not?谢谢 我可以检查客户是否已处置? thank you谢谢你
First off -- there's no reason to spam the question several times.首先 - 没有理由多次发送垃圾邮件问题。
But the answer is simply to use a try/catch for the ObjectDisposedException, this is pretty much the easiest way.但答案只是对 ObjectDisposedException 使用 try/catch,这几乎是最简单的方法。
try
{
/* access myTcpClient */
}
catch (ObjectDisposedException)
{
/* do some behaviour based on exception */
}
And that's all:)就这样:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.