private void ReceiveEvent(EventCode eventCode, Func<EventData, bool> checkAction) { try { this.peer.Service(); lock (this.peerListener.EventList) { while (this.peerListener.EventList.Count > 0) { var ev = this.peerListener.EventList[0]; this.peerListener.EventList.RemoveAt(0); if ((byte)ev.Code == (byte)eventCode && checkAction(ev)) { this.receivedEvent = ev; this.OnEventReceived(); this.resetEvent.Set(); return; } } } if (this.stopWatch.ElapsedMilliseconds > Settings.WaitTimeMultiOp) { Interlocked.Increment(ref exceptions); log.ErrorFormat("client {0} did not receive event {2} in time. {1}ms waited", this.Username, this.stopWatch.ElapsedMilliseconds, eventCode); } else { this.fiber.Schedule(() => this.ReceiveEvent(eventCode, checkAction), 10); } } catch (Exception e) { this.HandleException(e); } }
public void BeginReceiveEvent(EventCode eventCode, Func<EventData, bool> checkAction, int delay) { this.stopWatch.Reset(); this.fiber.Schedule( () => { this.stopWatch.Start(); this.ReceiveEvent(eventCode, checkAction); }, delay); }
/// <summary> /// The begin receive event. /// </summary> /// <param name = "client"> /// The client. /// </param> /// <param name = "eventCode"> /// The event code. /// </param> /// <param name = "delay"> /// The delay. /// </param> private static void BeginReceiveEvent(Client client, EventCode eventCode, int delay) { client.BeginReceiveEvent(eventCode, d => true, delay); }
/// <summary> /// The end receive event. /// </summary> /// <param name = "client"> /// The client. /// </param> /// <param name = "eventCode"> /// The event EventCode. /// </param> /// <returns> /// the received event /// </returns> private static EventData EndReceiveEvent(Client client, EventCode eventCode) { EventData data; Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received"); Assert.AreEqual(eventCode, (EventCode)data.Code); return data; }
/// <summary> /// The begin receive event. /// </summary> /// <param name = "client"> /// The client. /// </param> /// <param name = "eventCode"> /// The event code. /// </param> /// <param name = "checkAction"> /// The check action. /// </param> /// <param name = "delay"> /// The delay. /// </param> private static void BeginReceiveEvent(Client client, EventCode eventCode, Func<EventData, bool> checkAction, int delay) { client.BeginReceiveEvent(eventCode, checkAction, delay); }