private async void btnSend_Click(object sender, EventArgs e) { var svc = new SmlComServiceClient(); var activeStations = SystemCtrl.GetAllStations() .Where(s => s.IsOccupiedByDevice && !string.IsNullOrWhiteSpace(s.Device.GetParameterScanValue(ParameterTagId.PcbBarCode))) .ToList(); if (!activeStations.Any()) { MessageBox.Show("Keine Station mit gescannten Reallin Barcodes gefunden"); return; } var comPorts = activeStations.Select(s => new CommunicationPort() { ComPortName = s.ComAddress, MeterType = MeterType.Basemeter }).ToArray(); // update scan results foreach (var station in activeStations) { var device = station.Device; this.deviceRepository.UpdateDevice(device); } try { var result = await svc.ConfigurePortsAsync(comPorts, new Guid()); var guid = Guid.Parse(result); var tasks = activeStations.Select( s => s.ProcessDevice(svc, guid, comPorts.Single(p => p.ComPortName == s.ComAddress), this.cts.Token)).ToArray(); await Task.WhenAll(tasks); } catch (Exception ex) { MessageBox.Show(ex.Message); } this.LoadDevices(); }