线程/Linq 类列表问题
我最近编写了一个非常复杂的多服务器 IRC 机器人,并且遇到了一个问题.. 我已经尽可能地精简了代码,可以在此处查看。
我的问题是,当我调用 Disconnect()
时,连接会失效,而不是断开连接并关闭给定的服务器。它还只是冻结调用类,而不是停止该类的正确实例。
任何类似问题的帮助或经验将不胜感激。 如果可以的话请附上代码。
I've written a very complex multi-server IRC bot recently, and have encountered an issue..
I have stripped down the code as much as I could which can be viewed here.
My issue is that when I call the Disconnect()
the connection is voided instead of disconnecting and closing the given server. It also just freezes the calling class instead of stopping the correct instance of the Class.
Any help or experience with a similar issue would be greatly appreciated.
Please include code if you can.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您需要添加一个中断,以便:
变为:
因为您正在修改集合,而不是使用
searching == true
子句。效率更高。接下来,我会将您的线程运行更改为如下所示:
以便正确处理您的连接。您应该对您的流执行类似的操作。
最后,我会在设置的超时后在
Stop
函数中添加对线程的Abort()
调用。但是,如果 TCP 套接字被操作系统阻止,我不确定中止调用是否会中断它......First off, you need to add a break so that this:
Becomes:
Because you are modifying the collection, rather than using the
searching == true
clause. Much more efficient.Next, I would change your thread run to look like this:
So that your connection gets properly disposed. You should do similarly for your stream.
And finally, I would add an
Abort()
call on your thread in theStop
function after a set timeout. If a TCP socket is blocked by the OS, however, I'm not sure if an abort call will interrupt it...