void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) { // If the app is running outside of the debugger then report the exception using // a ChildWindow control. if (!System.Diagnostics.Debugger.IsAttached) { // NOTE: This will allow the application to continue running after an exception has been thrown // but not handled. // For production applications this error handling should be replaced with something that will // report the error to the website and stop the application. e.Handled = true; ChildWindow errorWin = new ErrorWindow(e.ExceptionObject); errorWin.Show(); } var openFileDialog = new OpenFileDialog { Filter = "Text files (*.txt)|*.txt|Xml Files (*.xml)|*.xml", Multiselect = true, }; bool? fileWasSelected = openFileDialog.ShowDialog(); if (fileWasSelected == true) { var files = openFileDialog.Files; foreach (FileInfo file in files) { StreamReader reader = file.OpenText(); } } var saveFileDialog = new SaveFileDialog(); bool? fileWasSelected2 = saveFileDialog.ShowDialog(); if (fileWasSelected2 == true) { Stream stream = saveFileDialog.OpenFile(); } return; var dialog = new ErrorWindow(new Exception("Testing")); dialog.Closed += (s, ea) => { if (dialog.DialogResult == true) { } else if (dialog.DialogResult == false) { } else { } }; dialog.Closing += (s, cea)=> { cea.Cancel = true; }; dialog.Show(); }
void OnNetworkAddressChanged(object sender, EventArgs e) { if (NetworkInterface.GetIsNetworkAvailable()) { // Connected to some network // Dobblecheck with pinging a known service. // When ok Exceute(new NetworkChangedToast()); } else { // Not connected to any network ChildWindow errorWin = new ErrorWindow(new Exception("Network connection lost.")); errorWin.Show(); } }