简体   繁体   English

.NET远程处理TcpChannel超时问题的解决方法

[英]Workaround for .NET Remoting TcpChannel Timeout Issue

Since I (and many other people on the internet) are unable to configure the client-side TcpChannel timeout when using .NET Remoting (please don't suggest proper fixes, I've literally tried everything, and no WCF suggestions please), I have come up with what seems like a decent workaround to creating a client-side timeout we can configure. 由于我(和Internet上的许多其他人)在使用.NET Remoting时无法配置客户端TcpChannel超时(请不要提出适当的修复程序,我已经尝试了所有方法,并且没有WCF建议),我提出了一种似乎不错的解决方法来创建我们可以配置的客户端超时。 If I feed each Remoting call through a separate timer thread, and the call either times out or throws an Exception, then I can kill the thread and assume that the server is down. 如果我通过一个单独的计时器线程提供每个Remoting调用,并且该调用超时或引发异常,则可以杀死该线程并假定服务器已关闭。

However, I ran this by another co-worker, and he was adamant that I could cause a deadlock in the native machine code of .NET by doing this. 但是,我是由另一位同事运行的,他坚决认为这样做可能会导致.NET的本机代码陷入僵局。 I've read other instances of this type of technique working on the internet like this post here , so I am unsure if worrying about a deadlock is really something I should have to worry about here. 我已经在互联网上阅读过这种技术的其他实例,如本文中的这篇文章 ,所以我不确定担心死锁真的是我应该在这里担心的事情。 I can see it maybe being a problem if the thread were to abort in the middle of sending or receiving something, but not if we're just waiting on a response. 我可以看到,如果线程在发送或接收消息的过程中中止,则可能是一个问题,但如果我们只是在等待响应,则不会出现问题。

Since Dan didn't post an answer, only commented, I attribute this answer to him. 由于Dan没有发布答案,仅发表了评论,因此我将此答案归功于他。 It seems that this method of managing a timeout is fine, as long as you take precautionary steps to ensure the thread execution does not continue in the event of a timeout. 看来,只要您采取预防措施以确保在发生超时时线程执行不会继续,这种管理超时的方法就可以了。 I also recommend against using Thread.Abort unless you know what you are doing. 我也建议不要使用Thread.Abort,除非您知道自己在做什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM