public bool Initialize(string?devicePath = null) { if (initialized) { return(false); } try { SyncModel = new TrippLiteUPS(false); if (SyncModel != null && SyncModel.Connected == false) { waitInit = new Thread(() => { for (var i = 0; i < MaxTries; i++) { Thread.Sleep(100); try { SyncModel.Connect(); } catch (Exception ex) { MessageBoxEx.Show( $"Error Opening HID Battery: {ex.Message}", "Initialization Failure", MessageBoxExType.OK, MessageBoxExIcons.Exclamation); } if (SyncModel is object && SyncModel.Connected) { Dispatcher.Invoke(() => { initialized = true; InternalInit(); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(TrippLite))); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Properties))); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ProminentProperties))); ViewModelInitialized?.Invoke(this, new EventArgs()); }); waitInit = null; return; } } }); waitInit.SetApartmentState(ApartmentState.MTA); waitInit.IsBackground = false; waitInit.Start(); return(false); } } catch { return(false); } initialized = true; InternalInit(); ViewModelInitialized?.Invoke(this, new EventArgs()); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(TrippLite))); return(true); }
private void OpenPowerClick(object sender, MouseButtonEventArgs e) { var h = new System.Windows.Interop.WindowInteropHelper(this); TrippLiteUPS.OpenSystemPowerOptions(h.Handle); }