private void WorkerThread_DoWork(object sender, DoWorkEventArgs e) { while (!pausado) { Thread.Sleep(1000); CondPartida est = verVez(); if (est == CondPartida.acabou) { fimDeJogo(); } else if (est == CondPartida.minhaVez) { jogarAutomatico(); listarPontos(); } if (workerThread.CancellationPending) { // this is important as it set the cancelled property of RunWorkerCompletedEventArgs to true e.Cancel = true; break; } } }
///////////////////////////////////////////////////////////// public void Jogar(Compra c) { string txt = Jogo.Jogar(jogador.id, jogador.senha, c.tipo, c.fabrica, c.azulejo, c.modelo); Console.WriteLine("joguei"); Invoke((MethodInvoker) delegate { lblErro.Text = txt; }); CondPartida est = verVez(); if (est == CondPartida.acabou) { fimDeJogo(); } else if (est == CondPartida.minhaVez) { atualizarAzulejos(); } }//Manda um pedido de compra