mkdir
code
cd
git init
git remote add -f origin https://github.com/karenpayneoregon/csharp-features
git sparse-checkout init --cone
git sparse-checkout add ExceptionHandling
git sparse-checkout add ThreadExceptionWindowsFormsApp
git pull origin master
:clean-up
del .gitattributes
del .gitignore
del .yml
del .editorconfig
del *.md
del *.sln
01.
using
System;
02.
System.Windows.Forms;
03.
ExceptionHandling;
04.
05.
/*
06.
* TODO Change this namespace to your project namespace
07.
*/
08.
namespace
ThreadExceptionWindowsFormsApp
09.
{
10.
/// <summary>
11.
/// Rig for unhandled exceptions.
12.
/// Note Text property set on error form is for demo purposes only
13.
/// </summary>
14.
static
class
Program
15.
16.
17.
[STAThread]
18.
void
Main()
19.
20.
21.
Application.SetHighDpiMode(HighDpiMode.SystemAware);
22.
Application.EnableVisualStyles();
23.
Application.SetCompatibleTextRenderingDefault(
false
);
24.
25.
// Handling UI thread exceptions to the event.
26.
Application.ThreadException += UnhandledExceptions.Application_ThreadException;
27.
28.
// For handling non-UI thread exceptions to the event.
29.
AppDomain.CurrentDomain.UnhandledException +=
30.
UnhandledExceptions.CurrentDomain_UnhandledException;
31.
32.
// Indicates capturing exception has completed
33.
UnhandledExceptions.OnProcessingCompletedEvent += OnProcessingCompletedEvent;
34.
35.
// TODO Change this to your startup form
36.
Application.Run(
new
Form1());
37.
}
38.
39.
/// Display window informing application most close
40.
41.
private
OnProcessingCompletedEvent()
42.
43.
var f =
AppErrorForm { Text = @
"Your title goes here"
};
44.
f.ShowDialog();
45.
Application.Exit();
46.
47.
48.