-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.xaml.cs
49 lines (44 loc) · 1.88 KB
/
App.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;
namespace PdfSorter
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
private void App_OnStartup(object sender, StartupEventArgs e)
{
Current.DispatcherUnhandledException += AppDispatcherUnhandledException;
}
private void AppDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
e.Handled = true;
string errorMessage =
string.Format(
"An application error occurred.\nPlease check whether your data is correct and repeat the action. If this error occurs again there seems to be a more serious malfunction in the application, and you better close it.\n\nError:{0}\n\nDo you want to continue?\n(if you click Yes you will continue with your work, if you click No the application will close)",
e.Exception.Message + (e.Exception.InnerException != null
? "\n" +
e.Exception.InnerException.Message
: null));
if (
MessageBox.Show(errorMessage, "Application Error", MessageBoxButton.YesNoCancel, MessageBoxImage.Error) ==
MessageBoxResult.No)
{
if (MessageBox.Show(
"WARNING: The application will close. Any changes will not be saved!\nDo you really want to close it?",
"Close the application!", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning) ==
MessageBoxResult.Yes)
{
Current.Shutdown();
}
}
}
}
}