private void UtilityMessageSent(IAsyncResult result) { if ((result != null) && (result.AsyncState != null)) { IPeerNeighbor owner = this.owner; if (((owner != null) && PeerNeighborStateHelper.IsConnected(owner.State)) && !result.CompletedSynchronously) { AsyncUtilityState asyncState = (AsyncUtilityState)result.AsyncState; Message message = asyncState.message; UtilityInfo umessage = asyncState.info; bool flag = false; if (umessage == null) { throw Fx.AssertAndThrow("expecting a UtilityInfo message in the AsyncState!"); } try { owner.EndSend(result); } catch (Exception exception) { if (Fx.IsFatal(exception)) { flag = true; throw; } if (this.HandleSendException(owner, exception, umessage) != null) { throw; } DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information); } finally { if (!flag) { message.Close(); } } EventHandler utilityInfoSent = this.UtilityInfoSent; if (utilityInfoSent != null) { utilityInfoSent(this, EventArgs.Empty); } } } }
void UtilityMessageSent(IAsyncResult result) { if (result == null || result.AsyncState == null) { return; } IPeerNeighbor host = this.owner; if (host == null || !PeerNeighborStateHelper.IsConnected(host.State)) { return; } if (result.CompletedSynchronously) { return; } AsyncUtilityState state = (AsyncUtilityState)result.AsyncState; Fx.Assert(state != null, "IAsyncResult.AsyncState does not contain AsyncUtilityState"); Message message = state.message; UtilityInfo umessage = state.info; bool fatal = false; if (!(umessage != null)) { throw Fx.AssertAndThrow("expecting a UtilityInfo message in the AsyncState!"); } try { host.EndSend(result); } catch (Exception e) { if (Fx.IsFatal(e)) { fatal = true; throw; } if (null != HandleSendException(host, e, umessage)) { throw; } DiagnosticUtility.TraceHandledException(e, TraceEventType.Information); } finally { if (!fatal) { Fx.Assert(!result.CompletedSynchronously, "result.CompletedSynchronously"); message.Close(); } } EventHandler handler = UtilityInfoSent; if (handler != null) { handler(this, EventArgs.Empty); } }