public void StopTask() { if (this.task != null) { this.task.Stop(); this.task = null; } }
private void btnStart_Click(object sender, RoutedEventArgs e) { if (!this.Check()) { return; } this.isDoing = !this.isDoing; this.btnStart.Content = this.isDoing ? "停止任务" : "启动任务"; if (this.isDoing) { this.task = new TaskRT(this.batteryList.ToList(), this.portConfig); this.task.Start(); } else { if (this.task != null) { this.task.Stop(); this.task = null; } } this.btnSync.IsEnabled = !this.isDoing; }