added samples
[windows-sources.git] / sdk / samples / WPFSamples / CrossThreadExceptionRaising_UIThread / csharp / app.xaml.cs
blobefb724d8b47ee204bfdf2371015fd751dd3a5837
1 using System; // Exception
2 using System.Text; // StringBuilder
3 using System.Windows; // Application, MessageBox
4 using System.Windows.Threading; // Dispatcher, DispatcherUnhandledExceptionEventArgs
6 namespace SDKSample
8 public partial class App : Application
10 void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
12 // Display exception message
13 StringBuilder sb = new StringBuilder();
14 sb.AppendFormat("{0}\n", e.Exception.InnerException.Message);
15 sb.AppendFormat("{0}\n", e.Exception.Message);
16 sb.AppendFormat("Exception handled on main UI thread {0}.", e.Dispatcher.Thread.ManagedThreadId);
17 MessageBox.Show(sb.ToString());
19 // Keep application running in the face of this exception
20 e.Handled = true;