private static void ProcessData(IAsyncResult ar) { UdpClient c = (UdpClient)ar.AsyncState; IPEndPoint receivedIpEndPoint = new IPEndPoint(IPAddress.Any, 0); Byte[] receivedBytes = c.EndReceive(ar, ref receivedIpEndPoint); DrawingData receivedData = DrawingData.ToData(receivedBytes); ClientInfo client = FindClient(receivedIpEndPoint); if (client != null) { receivedData.ClientID = client.ID; if (receivedBytes.Length > 17) { client.NewLine = true; } dataQueue.Enqueue(receivedData); } c.BeginReceive(ProcessData, ar.AsyncState); }
private void ProcessData(IAsyncResult ar) { if (!shouldStop) { UdpClient c = (UdpClient)ar.AsyncState; IPEndPoint receivedIpEndPoint = new IPEndPoint(IPAddress.Any, 0); Byte[] receivedBytes = c.EndReceive(ar, ref receivedIpEndPoint); DrawingData receivedData = DrawingData.ToData(receivedBytes); if (receivedBytes.Length > 17) { lastPoints[receivedData.ClientID] = null; lastColors[receivedData.ClientID] = Color.FromArgb(receivedData.A, receivedData.R, receivedData.G, receivedData.B); } paintSurface.Dispatcher.Invoke(new AddLineToCanvasDelegate(AddLineToCanvas), new DrawingData[] { receivedData }); c.BeginReceive(ProcessData, ar.AsyncState); } else { return; } }