private void OnCommandCanExecute(object sender, CanExecuteRoutedEventArgs e) { var pararmeter = CommandParameter ?? e.Parameter; if (CommandTo != null) { e.CanExecute = CommandTo.CanExecute(pararmeter); } }
void worker_DoWork(object sender, DoWorkEventArgs e) { while (IsRunning) { if (!IsConnected) { client = new TcpClient(); client.ReceiveTimeout = 10000; client.SendTimeout = 10000; try { client.Connect("localhost", mc.Config.ExternalPort); IsConnected = true; } catch (Exception ex) { if (ClientException != null) { ClientException(this, new ClientExceptionEventArgs(ex)); Disconnect(); break; } } } else { try { Receive(); if (ticker >= tickerMax) { PacketGenerator gen = new PacketGenerator(); gen.Add(PacketBytes._0x00_KeepAlive_0x00); client.Client.Send(gen.ToByteArray()); if (moveAndLookReceived && !teleported) { teleported = true; if (teleportTo != null) { CommandTo cmd = new CommandTo(mc); cmd.TriggerPlayer = Name; cmd.Execute(teleportTo, "", "", ""); } } ticker = 0; } ticker++; if (tickerMovement >= tickerMovementMax) { Move(0); tickerMovement = 0; } tickerMovement++; } catch (Exception ex) { if (ClientException != null) { ClientException(this, new ClientExceptionEventArgs(ex)); } try { Disconnect(); break; } catch (Exception ex2) { if (ClientException != null) { ClientException(this, new ClientExceptionEventArgs(ex2)); } } } } if (worker.CancellationPending) { Disconnect(); break; } Thread.Sleep(1); } IsConnected = false; }
private void OnCommandExecuted(object sender, ExecutedRoutedEventArgs e) { var pararmeter = CommandParameter ?? e.Parameter; CommandTo.Execute(pararmeter); }