Example #1
0
 /// <summary>
 /// Monitora a conexão com o servidor a cada 6 segundos. Roda em uma thread paralela a principal para fazer a verificação. Se coenectado, habilita mensagens,
 /// preenche grid de usuários e jogadores, o label do status do jogador logado, o campo de eventos pra ver se tem novas mensagens.
 /// Se contiver vencedor no campo de eventos, reseta a mão de cartas e o texto de eventos
 /// Se perder conexão com o servidor, limpa os campos e desabilita botões.
 /// </summary>
 public void KeepAlive()
 {
     while (btStartQuitGame.Text == "Sair")
     {
         Movements monitore = new Movements();
         if (monitore.KeepAlive())
         {
             this.Invoke(new Action(() => FillDataGrid(monitore.Users, monitore.GetPlayers())));
             UpdatePlayerStatus();
             InvokeComponentEnableAction(true, btSendMessage, tbMessage, comboBox1);
             this.Invoke(new Action(() => {
                 if (tbEvents.Text.Contains("vencedor"))
                 {
                     Movements.Cards.Clear();
                     tbEvents.Text = "";
                 }
             }));
             this.Invoke(new Action(() => tbEvents.AppendText(monitore.getOldestMessage())));
         }
         else
         {
             btStartQuitGame.Text  = "Jogar";
             tbCards.Text          = string.Empty;
             tbEvents.Text         = string.Empty;
             tbScore.Text          = string.Empty;
             tbMessage.Text        = string.Empty;
             btRequestCard.Enabled = false;
             btSendMessage.Enabled = false;
             comboBox1.Enabled     = false;
             btStopTurn.Enabled    = false;
             tbMessage.Enabled     = false;
             ClearDataGrids();
             MessageBox.Show(this, "Conexão com servidor Perdida", "Conexão Perdida", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }