.NET 远程处理中的事件问题

发布于 2024-07-30 03:46:13 字数 588 浏览 7 评论 0原文

学习INGO RAMMER的“Advanced .NET Remoting”,我尝试使用以下代码向客户端触发事件:

foreach (Delegate del in MessageArrived.GetInvocationList()) 
{
try 
{
mah = (MessageArrivedHandler) del;
mah(msg);
} 
catch (Exception e) 
{
Console.WriteLine("Exception occured, will remove Delegate");
MessageArrived -= mah;
}
}

当我在客户端模拟网络问题时,客户端的委托按预期被-=删除,并且MessageArrived变为null 。

但随着网络恢复,客户端将尝试连接、获取远程对象并重新注册事件,就像启动时一样,看起来重新注册成功,因为 MessageArrived 不为空。

问题是我仍然遇到异常将调用然后被删除的委托。 据我了解,这不会引起期望,因为。 客户端再次在线,并且 re-connect() 和 connect() 方法共享相同的代码...

任何人都可以帮助我吗?

Learning from INGO RAMMER's "Advanced .NET Remoting", I tried to use the following codes for firing events to clients:

foreach (Delegate del in MessageArrived.GetInvocationList()) 
{
try 
{
mah = (MessageArrivedHandler) del;
mah(msg);
} 
catch (Exception e) 
{
Console.WriteLine("Exception occured, will remove Delegate");
MessageArrived -= mah;
}
}

When I simulated a network problem in client side, the client's delegate was removed by -= as expected, and the MessageArrived became null.

But as the network was restored, the client will try to connect, get remote object and re-register event as it does same for startup, it seems the re-registeration was successful as the MessageArrived was not null.

The problem is I still got the exception will invoke the delegate which was then removed. As I understand, this shall not raise expcetion coz. the client is online again and re-connect() and connect() method shares the same codes...

Can anybody help me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不寐倦长更 2024-08-06 03:46:14

检查事件注销是否正常。 当客户端断开连接时,最好优雅地取消注册事件。

Check whether the unregistering of events is happening properly or not. When the client is disconnected it is preferable to unregister the events gracefully.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文