/// <summary> /// 进行指定的事件回调 /// </summary> /// <param name="sync">true表示同步回调,false则是异步。这仅在启用跨线程调用时有效</param> /// <param name="handler">事件句柄</param> /// <param name="client">当前的客户端</param> /// <param name="args">要回调用的事件数据</param> static void SendOrPostCallback <T>(bool sync, EventHandler <T> handler, IPMClient client, T args) where T : EventArgs { if (handler == null) { return; } if (EnableThreadContextSynchroization && client.ThreadContext != null) { if (sync) { client.ThreadContext.Send(_ => handler(client, args), null); } else { client.ThreadContext.Post(_ => handler(client, args), null); } } else { handler(client, args); } }
/// <summary> /// 进行指定的事件回调 /// </summary> /// <param name="sync">true表示同步回调,false则是异步。这仅在启用跨线程调用时有效</param> /// <param name="handler">事件句柄</param> /// <param name="client">当前的客户端</param> static void SendOrPostCallback(bool sync, EventHandler handler, IPMClient client) { if (handler == null) { return; } if (EnableThreadContextSynchroization && client.ThreadContext != null) { if (sync) { client.ThreadContext.Send(_ => handler(client, EventArgs.Empty), null); } else { client.ThreadContext.Post(_ => handler(client, EventArgs.Empty), null); } } else { handler(client, EventArgs.Empty); } }
/// <summary> /// 当UDP网络出现错误的时候触发 /// </summary> /// <param name="client">引发此事件的源对象</param> /// <param name="e">包含此事件的参数</param> internal static void OnUdpNetworkError(IPMClient client, EventArgs e) { SendOrPostCallback(false, UdpNetworkError, client); }
/// <summary> /// 引发 <see cref="TcpThreadFileSystemOperationError" /> 事件 /// </summary> /// <param name="sender">引发此事件的源对象</param> /// <param name="ea">包含此事件的参数</param> internal static void OnTcpThreadFileSystemOperationError(IPMClient sender, FileSystemOperationErrorEventArgs ea) { SendOrPostCallback(false, TcpThreadFileSystemOperationError, sender, ea); }
/// <summary> /// 触发重新发送事件 /// </summary> /// <param name="client">引发此事件的源对象</param> /// <param name="e">包含事件的参数</param> internal static void OnUdpPackageResend(IPMClient client, PackageSendEventArgs e) { SendOrPostCallback(false, UdpPackageResend, client, e); }
/// <summary> /// 当事件触发时调用 /// </summary> /// <param name="client">引发此事件的源对象</param> /// <param name="e"></param> internal static void OnUdpIpValidateRequired(IPMClient client, IpValidateRequiredEventArgs e) { SendOrPostCallback(false, UdpIpValidateRequired, client, e); }
/// <summary> /// 主机消息包被丢弃时,被调用 /// </summary> /// <param name="client">引发此事件的源对象</param> /// <param name="e">包含事件的参数</param> internal static void OnUdpPackageDroped(IPMClient client, NetworkPackageEventArgs e) { SendOrPostCallback(false, UdpPackageDroped, client, e); }