【问题标题】:Remoting set timeout远程设置超时
【发布时间】:2010-06-23 14:35:18
【问题描述】:

.NET 远程处理在我的brownfield 应用程序中使用。我们决定为我们的远程处理方法设置超时。

System.Collections.IDictionary properties = new System.Collections.Hashtable();
properties["name"] = Ipc_Channel_Name;
properties["timeout"] = 1 * 1000;

IChannel clientChannel = new IpcClientChannel(properties, null);
ChannelServices.RegisterChannel(clientChannel, false);

问题是超时似乎不起作用。我通过在调用的代码中设置System.Threading.Thread.Sleep(5 * 1000); 来检查它。是IpcClientChannel不支持超时的原因吗?

如何设置超时时间?

【问题讨论】:

  • 有什么想法吗?这个问题仍然存在。

标签: c# .net timeout remoting .net-remoting


【解决方案1】:

设置 IpcClientChannel 超时的属性名称不是“超时”。名称是“connectionTimeout”。请参阅 Client Channel Properties (MSDN)。那么它应该可以工作了。

System.Collections.IDictionary properties = new System.Collections.Hashtable();
properties["name"] = Ipc_Channel_Name;
properties["connectionTimeout"] = 1 * 1000;

IChannel clientChannel = new IpcClientChannel(properties, null);
ChannelServices.RegisterChannel(clientChannel, false);

【讨论】:

  • 嗨,杰霍夫。谢谢你的回答。来自 MSDN:“connectiontimeout 是一个整数,它指定等待成功连接的毫秒数。0 或 -1 表示无限超时时间。默认为无限。”如果将连接超时设置为 1*1000 和 System.Threading.Thread.Sleep(5 * 1000);在调用的代码中,你不会得到任何异常。它将等待 5 秒。我通过修改客户端的代码解决了这个问题。
  • @MegaHerz 对不起,但我不明白。您将 connectiontimeout 设置为 1000 毫秒,服务器休眠 5000 毫秒 > 1000 毫秒。它肯定会超时。为什么你没有得到一个例外?你的意思是这是一个错误?
  • 如果您正在寻找 Client Channel Properties 页面,它已被移动。它现在在 MSDN here.
猜你喜欢
  • 2011-08-07
  • 1970-01-01
  • 2021-09-08
  • 2014-10-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多