public void Write(Msg msg, Object callback) { LastWriteTime = DateTime.Now; msg.SendTime = LastWriteTime; if (msg == null) { logReport.OnWarningReport("msg is null"); return; } if (IsOpen()) { cmdDelegate.AddCmdCallbackMap(msg, callback); IoHandler.Write(this, msg); logReport.OnLogReport("sessionid" + id + "->send:" + msg.ToString() + ",time:" + LastWriteTime); } else { logReport.OnWarningReport("sessionid" + id + "->msg" + msg.ToString() + " send time out,net is broken"); cmdDelegate.OnMsgRev(msg); if (IoHandler != null) { IoHandler.Trigger(new TimeOutEvent(this, msg)); } } }
public void Send(Msg msg, object callback) { if (callback != null) { DateTime now = DateTime.Now; msg.SendTime = now; } //实例委托 AsyncEventHandler asy = new AsyncEventHandler(HttpAsyncEvent); cmdDelegate.AddCmdCallbackMap(msg, callback); //异步调用开始,没有回调函数和AsyncState,都为null asy.BeginInvoke(msg, null, asy); }