private void ListenLoop() { try { while (m_Receiver.State != OscSocketState.Closed) { // if we are in a state to recieve if (m_Receiver.State == OscSocketState.Connected) { // get the next message // this will block until one arrives or the socket is closed OscPacket packet = m_Receiver.Receive(); switch (m_Listener.ShouldInvoke(packet)) { case OscPacketInvokeAction.Invoke: packetCounter.Increment(); //textBoxBuffer.WriteLine("Received packet"); textBoxBuffer.WriteLine(packet.ToString()); m_Listener.Invoke(packet); break; case OscPacketInvokeAction.DontInvoke: textBoxBuffer.WriteLine("Cannot invoke"); textBoxBuffer.WriteLine(packet.ToString()); break; case OscPacketInvokeAction.HasError: textBoxBuffer.WriteLine("Error reading osc packet, " + packet.Error); textBoxBuffer.WriteLine(packet.ErrorMessage); break; case OscPacketInvokeAction.Pospone: textBoxBuffer.WriteLine("Posponed bundle"); textBoxBuffer.WriteLine(packet.ToString()); break; default: break; } } } } catch (Exception ex) { // if the socket was connected when this happens // then tell the user if (m_Receiver.State == OscSocketState.Connected) { textBoxBuffer.WriteLine("Exception in listen loop"); textBoxBuffer.WriteLine(ex.Message); } } }