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!");
}
}