Solution to exception when the event in remoting cannot find the subscriber

Source: Internet
Author: User

1. [oneway] oneway attributes:

When an event cannot be sent, an exception message is returned normally. If onewayattribute is added, the event will be sent in one way. If an exception occurs at this time, the system will automatically throw the exception information. If no exception information is returned, the sender determines that the message is successfully sent.ProgramThe error client is ignored and the client can still receive messages;

2. Check the delegated chain:

It is when the sender checks the delegate chain. And capture exceptions in the traversal of the delegate chain. A prompt is displayed when one of the delegates has an exception. Then, we continue to traverse the subsequent delegation, which not only ensures the prompt of exception information, but also ensures that other subscribers receive messages normally. Therefore, I modified the remote object in this example, commented out [oneway], and modified the broadcastinfo () method:

// [Oneway]
Public   Void Send ( String Info)
{
If (Myevent ! =   Null )
{
Eventhandler tempevent =   Null ;

Int Index =   1 ; // Record the index entrusted by the event subscriber. for easy identification, it starts from 1.
Foreach (Delegate del In Myevent. getinvocationlist ())
{
Try
{
Tempevent=(Eventhandler) del;
Tempevent (Info );
}
Catch
{< br> MessageBox. show ( " event subscriber " + index. tostring () + " an error occurs, the system will cancel event subscription! " );
myevent -= tempevent;
}
Index ++ ;
}
}
Else
{
MessageBox. Show ("An error occurred when the event was not subscribed or subscribed!");
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.