public void Run(object state, bool timedOut) { if (IsRunning == false) { lock (this) { if (!IsRunning) { IsRunning = true; long t = GetTimeoutLeft(); while (t <= 0) { OutPacket packet = Remove(); IConnection conn = client.ConnectionManager.ConnectionPool.GetConnection(packet.PortName); if (conn != null && packet != null && !conn.Policy.IsReplied(packet, false)) { if (packet.NeedResend()) { // 重发次数未到最大,重发 client.PacketManager.SendPacketAnyway(packet, packet.PortName); } else { // 触发操作超时事件 FireOperationTimeOutEvent(packet, packet.PortName); } } t = GetTimeoutLeft(); } IsRunning = false; // 继续等待 t 时间后再执行 // 先反注册原来的线程 this.RegisterdHandler.Unregister(this.WaitHandler); ThreadExcutor.RegisterIntervalObject(this, this, t, true); } } } }