/// <summary> /// Starts or kills the test /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void Start_Click(object sender, RoutedEventArgs e) { if ((string)Start.Content == "Start") { // Assigns the token source tokenSource = new CancellationTokenSource(); ct = tokenSource.Token; EnableDisableSettings(); if (!Client1Settings()) { return; } if ((bool)OneClient.IsChecked) { HostedMB.SlavesCreated = new bool[1]; await Task.Run(() => HostedMB.CreateHostedSlave1()); HostedMB.OutputPorts = new string[] { (string)Client1Serial.SelectedValue }; } else if ((bool)TwoClients.IsChecked) { HostedMB.SlavesCreated = new bool[2]; if (!Client2Settings()) { return; } await Task.Run(() => HostedMB.CreateHostedSlave1And2()); HostedMB.OutputPorts = new string[] { (string)Client1Serial.SelectedValue, (string)Client2Serial.SelectedValue }; } else { HostedMB.SlavesCreated = new bool[3]; if (!Client2Settings()) { return; } ; if (!Client3Settings()) { return; } await Task.Run(() => HostedMB.CreateHostedSlave1And2And3()); HostedMB.OutputPorts = new string[] { (string)Client1Serial.SelectedValue, (string)Client2Serial.SelectedValue, (string)Client3Serial.SelectedValue }; } if ((bool)LiveInput.IsChecked) { if (!Live()) { return; } } else { Generated(); } Start.Content = "Stop"; Start.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ff5252")); // The process has a set duration if ((bool)DurationCheckbox.IsChecked) { int hours = Convert.ToInt32(Hours.Text); int minutes = Convert.ToInt32(Minutes.Text); _time = TimeSpan.FromMinutes(hours * 60 + minutes); _timer = new DispatcherTimer(new TimeSpan(0, 0, 1), DispatcherPriority.Normal, delegate { Timer.Text = _time.ToString("c"); if (_time == TimeSpan.Zero) { _timer.Stop(); } _time = _time.Add(TimeSpan.FromSeconds(-1)); }, Application.Current.Dispatcher); _timer.Start(); await Task.Run(() => EndAfterDuration(hours, minutes)); Start.Content = "Start"; Start.IsEnabled = true; Start.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#33cc57")); EnableDisableSettings(); } } else { tokenSource.Cancel(); while (!ProcessKilled) { } Start.Content = "Start"; Start.IsEnabled = true; Start.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#33cc57")); EnableDisableSettings(); } }