public async void Run() { IsRunning = true; await Task.Run(async() => { while (IsRunning) { try { string response = await conn.WaitForResponse(); Tuple <string[], PacketType> packet = packetHandler.HandlePacket(response); switch (packet.Item2) { case PacketType.Status: StatusReceived?.Invoke(new StatusArgs(packet.Item1[1])); break; case PacketType.DoctorDisconnect: DoctorDisconnectReceived?.Invoke(new EventArgs()); break; case PacketType.Resistance: ResistanceReceived?.Invoke(new ResistanceArgs(packet.Item1[1])); break; case PacketType.Broadcast: BroadcastReceived?.Invoke(new BroadcastArgs(packet.Item1[1])); break; case PacketType.Message: MessageReceived?.Invoke(new MessageArgs(packet.Item1[1])); break; case PacketType.StopVR: StopReceived?.Invoke(new EventArgs()); break; } } catch (Exception e) { IsRunning = false; } } }); }
protected virtual void OnStopReceived(AMCPEventArgs e) { StopReceived?.Invoke(this, e); }