private void ServerLoop(object sender, DoWorkEventArgs e) { if (!Connection.StartConnection(CurrentConfig)) { OnConnectionClosed(false); return; } State = PopState.Authorization; OnConnectionOpened(); while (!ShutdownRequested) { if (CommandQueue.Count > 0) { PopCommand Cmd = null; bool Deq = CommandQueue.TryDequeue(out Cmd); if (!Connection.ExecuteCommand(Cmd)) { OnLineSentOrReceived(false, "PopCommand error for " + Cmd.ToString()); } System.Threading.Thread.Sleep(100); } else { System.Threading.Thread.Sleep(100); } } ShutdownRequested = false; Connection.CloseConnection(); Connection = null; OnConnectionClosed(State == PopState.Off); }
public void PushNewCommand(PopCommand NewCommand) { NewCommand.SetPopService(this); CommandQueue.Enqueue(NewCommand); }