void ShowPowerConfig(object sender, EventArgs e) { if (!IsHandleCreated) { return; } BeginInvoke(new Action(async() => { try { PowerConfigWindow.ShowPowerConfig(); } catch (Exception ex) { Logging.Stacktrace(ex); } })); }
public static void ShowPowerConfig() { //await Task.Delay(0); if (pcw != null) { try { pcw?.BringToFront(); return; } catch { } // don't care, if the above fails, the window doesn't exist and we can follow through after } lock (PowerConfig_lock) { try { using (pcw = new PowerConfigWindow()) { var res = pcw.ShowDialog(); if (pcw.DialogResult == DialogResult.OK) { Taskmaster.powermanager.AutoAdjust = pcw.newAutoAdjust; Log.Information("<<UI>> Power auto-adjust config changed."); // TODO: Call reset on power manager? } else { if (Taskmaster.Trace) { Log.Verbose("<<UI>> Power auto-adjust config cancelled."); } } } } catch { } // finally might not be executed otherwise finally { pcw?.Dispose(); pcw = null; } } }