DispatcherUnhandledExceptionEventArgs.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Diagnostics;
  3. using Avalonia.Interactivity;
  4. namespace Avalonia.Threading;
  5. /// <summary>
  6. /// Represents the method that will handle the <see cref="Dispatcher.UnhandledException"/> event.
  7. /// </summary>
  8. public delegate void DispatcherUnhandledExceptionEventHandler(object sender, DispatcherUnhandledExceptionEventArgs e);
  9. /// <summary>
  10. /// Provides data for the <see cref="Dispatcher.UnhandledException"/> event.
  11. /// </summary>
  12. public sealed class DispatcherUnhandledExceptionEventArgs : DispatcherEventArgs
  13. {
  14. private Exception _exception;
  15. private bool _handled;
  16. internal DispatcherUnhandledExceptionEventArgs(Dispatcher dispatcher) : base(dispatcher)
  17. {
  18. _exception = null!;
  19. }
  20. /// <summary>
  21. /// Gets the exception that was raised when executing code by way of the dispatcher.
  22. /// </summary>
  23. public Exception Exception => _exception;
  24. /// <summary>
  25. /// Gets or sets whether the exception event has been handled.
  26. /// </summary>
  27. public bool Handled
  28. {
  29. get
  30. {
  31. return _handled;
  32. }
  33. set
  34. {
  35. // Only allow to be set true.
  36. if (value)
  37. {
  38. _handled = value;
  39. }
  40. }
  41. }
  42. internal void Initialize(Exception exception, bool handled)
  43. {
  44. Debug.Assert(exception != null);
  45. _exception = exception;
  46. _handled = handled;
  47. }
  48. }