.NET 远程处理中的事件问题
学习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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查事件注销是否正常。 当客户端断开连接时,最好优雅地取消注册事件。
Check whether the unregistering of events is happening properly or not. When the client is disconnected it is preferable to unregister the events gracefully.