public void Stop() { if (UserThreads != null) { foreach (var user in UserThreads) { user.Abort(); } } foreach (ServerUser u in Users) { u.Client.Close(); } if (LobbyThread.ThreadState != ThreadState.Aborted) { Listener.Stop(); LobbyThread.Abort(); LobbyThread = null; } if (GameThread != null && GameThread.ThreadState != ThreadState.Aborted) { GameThread.Abort(); GameThread = null; } }
public void StartGame() { Listener.Stop(); LobbyThread.Abort(); GameThread = new Thread(() => { Queue = new ConcurrentQueue <ClassToSend>(); BlockingCollection <ClassToSend> bc = new BlockingCollection <ClassToSend>(Queue); StartThreads(bc); InitializeUsers(); RoundEnd(); RoundStart(); playersGuessing = Users.Count() - 1; DateTime time = DateTime.Now; PingTime = DateTime.Now; while (true) { SwitchRound(ref time, bc); Ping(); if (PlayerLeft) { foreach (ServerUser u in Users) { ClassToSend msg = new ClassToSend(); msg.Type = Type.CloseConnection; SendMessage(u, msg); } break; } SendingPicture(bc); //Preprakjanje } }); GameThread.IsBackground = true; GameThread.Start(); }