private Windows.Foundation.IAsyncAction OnDeviceRemoved(object sender, UsbDeviceInfo info) { var dispatcher = this.Dispatcher; IAsyncOperation <Windows.UI.Popups.IUICommand> dialogShowAsync = null; var uiThreadTasks = dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() => { if (this.SerialPortInfo != null) { if (this.SerialPortInfo.DeviceId == info.Id) { dialogShowAsync = (new Windows.UI.Popups.MessageDialog(info.Name + " has been removed.")).ShowAsync(); this.buttonWriteBulkOut.IsEnabled = false; this.buttonSendBreak.IsEnabled = false; this.buttonWriteBinary1.IsEnabled = false; this.buttonWriteBinary2.IsEnabled = false; this.textBlockDeviceInUse.Text = "No device selected."; this.textBlockDeviceInUse.Foreground = new SolidColorBrush(Windows.UI.Colors.OrangeRed); } } })); return(System.Threading.Tasks.Task.Run(async() => { await uiThreadTasks; if (dialogShowAsync != null) { await dialogShowAsync; } } ).AsAsyncAction()); }
private void OnDeviceAdded(object sender, UsbDeviceInfo info) { var dispatcher = this.Dispatcher; ((Action)(async() => { await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() => { this.comboBoxDevices1.Items.Add(new UsbDeviceComboBoxItem(info.Id, info.Name)); this.comboBoxDevices2.Items.Add(new UsbDeviceComboBoxItem(info.Id, info.Name)); if (this.comboBoxDevices1.SelectedIndex == -1) { if (this.previousSelectedDeviceId1 == info.Id || this.previousSelectedDeviceId1 == "") { this.comboBoxDevices1.SelectedIndex = 0; } } if (this.comboBoxDevices2.SelectedIndex == -1) { if (this.previousSelectedDeviceId2 == info.Id || this.previousSelectedDeviceId2 == "") { this.comboBoxDevices2.SelectedIndex = 0; } } })); } )).Invoke(); }
private void AddDeviceToComboBox(UsbDeviceInfo info) { this.comboBoxDevices.Items.Insert(0, new UsbDeviceComboBoxItem(info.Id, info.Name)); if (this.SerialPortInfo != null && this.SerialPortInfo.DeviceId == info.Id) { this.comboBoxDevices.SelectedIndex = 0; } else if (this.comboBoxDevices.SelectedIndex == -1) { if (this.previousSelectedDeviceId == info.Id || this.previousSelectedDeviceId == "") { this.comboBoxDevices.SelectedIndex = 0; } } }
private Windows.Foundation.IAsyncAction OnDeviceRemoved(object sender, UsbDeviceInfo info) { var dispatcher = this.Dispatcher; IAsyncOperation <Windows.UI.Popups.IUICommand> dialogShowAsync = null; var uiThreadTasks = dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() => { for (int i = 0; i < this.comboBoxDevices.Items.Count; i++) { var item = this.comboBoxDevices.Items[i] as UsbDeviceComboBoxItem; if (item.Id == info.Id) { bool isEnabled = this.comboBoxDevices.IsEnabled; this.comboBoxDevices.IsEnabled = true; this.comboBoxDevices.Items.RemoveAt(i); if (this.SerialPortInfo != null && this.SerialPortInfo.DeviceId == info.Id) { dialogShowAsync = new Windows.UI.Popups.MessageDialog(info.Name + " has been removed.").ShowAsync(); this.buttonDeviceDeselect_Click(null, null); if (this.comboBoxDevices.Items.Count > 0) { this.comboBoxDevices.SelectedIndex = 0; } } else { if (this.comboBoxDevices.SelectedIndex == -1) { this.comboBoxDevices.SelectedIndex = 0; } this.comboBoxDevices.IsEnabled = isEnabled; } return; } } })); return(System.Threading.Tasks.Task.Run(async() => { await uiThreadTasks; if (dialogShowAsync != null) { await dialogShowAsync; } } ).AsAsyncAction()); }
private void OnDeviceAdded(object sender, UsbDeviceInfo info) { var dispatcher = this.Dispatcher; if (dispatcher.HasThreadAccess) { this.AddDeviceToComboBox(info); } else { ((Action)(async() => { await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() => { this.AddDeviceToComboBox(info); })); } )).Invoke(); } }
private Windows.Foundation.IAsyncAction OnDeviceRemoved(object sender, UsbDeviceInfo info) { var dispatcher = this.Dispatcher; return(dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(async() => { var showMessageDialog = false; ComboBox[] comboBoxs = { this.comboBoxDevices1, this.comboBoxDevices2 }; foreach (var comboBoxDevices in comboBoxs) { for (int i = 0; i < comboBoxDevices.Items.Count; i++) { var item = comboBoxDevices.Items[i] as UsbDeviceComboBoxItem; if (item.DeviceId == info.Id) { if (this.buttonInitialize.IsEnabled == false && comboBoxDevices.SelectedIndex == i) { showMessageDialog = true; if (this.cancelTokenSrcOpRead != null) { this.buttonStopLoopback_Click(this, null); // cancel read op if possible. } } comboBoxDevices.Items.RemoveAt(i); if (comboBoxDevices.SelectedIndex == -1 && comboBoxDevices.Items.Count > 0) { comboBoxDevices.SelectedIndex = 0; } break; } } } if (showMessageDialog) { await(new Windows.UI.Popups.MessageDialog(info.Name + " has been removed.")).ShowAsync(); } }))); }
private Windows.Foundation.IAsyncAction OnDeviceRemoved(object sender, UsbDeviceInfo info) { var dispatcher = this.Dispatcher; return dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(async () => { var showMessageDialog = false; ComboBox[] comboBoxs = { this.comboBoxDevices1, this.comboBoxDevices2 }; foreach (var comboBoxDevices in comboBoxs) { for (int i = 0; i < comboBoxDevices.Items.Count; i++) { var item = comboBoxDevices.Items[i] as UsbDeviceComboBoxItem; if (item.DeviceId == info.Id) { if (this.buttonInitialize.IsEnabled == false && comboBoxDevices.SelectedIndex == i) { showMessageDialog = true; if (this.cancelTokenSrcOpRead != null) { this.buttonStopLoopback_Click(this, null); // cancel read op if possible. } } comboBoxDevices.Items.RemoveAt(i); if (comboBoxDevices.SelectedIndex == -1 && comboBoxDevices.Items.Count > 0) { comboBoxDevices.SelectedIndex = 0; } break; } } } if (showMessageDialog) { await (new Windows.UI.Popups.MessageDialog(info.Name + " has been removed.")).ShowAsync(); } })); }
private void OnDeviceAdded(object sender, UsbDeviceInfo info) { var dispatcher = this.Dispatcher; ((Action)(async () => { await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() => { this.comboBoxDevices1.Items.Add(new UsbDeviceComboBoxItem(info.Id, info.Name)); this.comboBoxDevices2.Items.Add(new UsbDeviceComboBoxItem(info.Id, info.Name)); if (this.comboBoxDevices1.SelectedIndex == -1) { if (this.previousSelectedDeviceId1 == info.Id || this.previousSelectedDeviceId1 == "") { this.comboBoxDevices1.SelectedIndex = 0; } } if (this.comboBoxDevices2.SelectedIndex == -1) { if (this.previousSelectedDeviceId2 == info.Id || this.previousSelectedDeviceId2 == "") { this.comboBoxDevices2.SelectedIndex = 0; } } })); } )).Invoke(); }
private Windows.Foundation.IAsyncAction OnDeviceRemoved(object sender, UsbDeviceInfo info) { var dispatcher = this.Dispatcher; IAsyncOperation<Windows.UI.Popups.IUICommand> dialogShowAsync = null; var uiThreadTasks = dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() => { if (this.SerialPortInfo != null && this.SerialPortInfo.DeviceId == info.Id) { dialogShowAsync = (new Windows.UI.Popups.MessageDialog(info.Name + " has been removed.")).ShowAsync(); if (this.cancelTokenSrcOpRead != null) { this.buttonStopWatching_Click(this, null); // cancel read op if possible. } this.buttonReadBulkIn.IsEnabled = false; this.buttonWatchBulkIn.IsEnabled = false; this.buttonStopWatching.IsEnabled = false; this.textBlockDeviceInUse.Text = "No device selected."; this.textBlockDeviceInUse.Foreground = new SolidColorBrush(Windows.UI.Colors.OrangeRed); } })); return System.Threading.Tasks.Task.Run(async () => { await uiThreadTasks; if (dialogShowAsync != null) { await dialogShowAsync; } } ).AsAsyncAction(); }
private void OnDeviceAdded(object sender, UsbDeviceInfo info) { }
private void OnDeviceAdded(object sender, UsbDeviceInfo info) { }
private Windows.Foundation.IAsyncAction OnDeviceRemoved(object sender, UsbDeviceInfo info) { var dispatcher = this.Dispatcher; IAsyncOperation<Windows.UI.Popups.IUICommand> dialogShowAsync = null; var uiThreadTasks = dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() => { for (int i = 0; i < this.comboBoxDevices.Items.Count; i++) { var item = this.comboBoxDevices.Items[i] as UsbDeviceComboBoxItem; if (item.Id == info.Id) { bool isEnabled = this.comboBoxDevices.IsEnabled; this.comboBoxDevices.IsEnabled = true; this.comboBoxDevices.Items.RemoveAt(i); if (this.SerialPortInfo != null && this.SerialPortInfo.DeviceId == info.Id) { dialogShowAsync = new Windows.UI.Popups.MessageDialog(info.Name + " has been removed.").ShowAsync(); this.buttonDeviceDeselect_Click(null, null); if (this.comboBoxDevices.Items.Count > 0) { this.comboBoxDevices.SelectedIndex = 0; } } else { if (this.comboBoxDevices.SelectedIndex == -1) { this.comboBoxDevices.SelectedIndex = 0; } this.comboBoxDevices.IsEnabled = isEnabled; } return; } } })); return System.Threading.Tasks.Task.Run(async () => { await uiThreadTasks; if (dialogShowAsync != null) { await dialogShowAsync; } } ).AsAsyncAction(); }
private void AddDeviceToComboBox(UsbDeviceInfo info) { this.comboBoxDevices.Items.Insert(0, new UsbDeviceComboBoxItem(info.Id, info.Name)); if (this.SerialPortInfo != null && this.SerialPortInfo.DeviceId == info.Id) { this.comboBoxDevices.SelectedIndex = 0; } else if (this.comboBoxDevices.SelectedIndex == -1) { if (this.previousSelectedDeviceId == info.Id || this.previousSelectedDeviceId == "") { this.comboBoxDevices.SelectedIndex = 0; } } }
private void OnDeviceAdded(object sender, UsbDeviceInfo info) { var dispatcher = this.Dispatcher; if (dispatcher.HasThreadAccess) { this.AddDeviceToComboBox(info); } else ((Action)(async () => { await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() => { this.AddDeviceToComboBox(info); })); } )).Invoke(); }