Better handling of errors when app is unable to access sinmai process for exiting
parent
db5e3c5903
commit
ed95e6eb35
|
@ -76,12 +76,16 @@ public partial class MainWindow : Window
|
|||
};
|
||||
}
|
||||
|
||||
private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
||||
private async void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
e.Cancel = true;
|
||||
await connector.Disconnect();
|
||||
foreach (Window childWindow in OwnedWindows)
|
||||
{
|
||||
childWindow.Close();
|
||||
}
|
||||
Closing -= MainWindow_Closing;
|
||||
Close();
|
||||
}
|
||||
|
||||
private async void ExitWithSinmaiLoop()
|
||||
|
@ -100,9 +104,14 @@ public partial class MainWindow : Window
|
|||
await Task.Delay(1000);
|
||||
}
|
||||
}
|
||||
var dataContext = (MainWindowViewModel)DataContext;
|
||||
|
||||
if (dataContext.IsExitWithSinmaiEnabled)
|
||||
{
|
||||
try
|
||||
{
|
||||
await sinamiProcess.WaitForExitAsync();
|
||||
Logger.Info("Sinmai exited");
|
||||
var dataContext = (MainWindowViewModel)DataContext;
|
||||
if (dataContext.IsExitWithSinmaiEnabled)
|
||||
{
|
||||
Logger.Info("Disconnecting from COM port before shutting down");
|
||||
|
@ -111,6 +120,16 @@ public partial class MainWindow : Window
|
|||
Application.Current.Shutdown();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Error("Failed to wait for sinmai to exit", ex);
|
||||
dataContext.IsExitWithSinmaiEnabled = false;
|
||||
Properties.Settings.Default.IsExitWithSinmaiEnabled = dataContext.IsExitWithSinmaiEnabled;
|
||||
Properties.Settings.Default.Save();
|
||||
MessageBox.Show("Failed to listen for Sinmai exit signal, is it running as admin?\n\nAutomatic exiting disabled.", "Failed to listen for Sinmai exit", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async void AutomaticTouchPanelPositioningLoop()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue