コード例 #1
0
        internal static async Task ExecuteInApplicationMonitorScope <C>(
            [NotNull] Func <C> notificationContextFactory,
            [NotNull] Func <ApplicationMonitorScope, Task> action) where C : INotificationContext
        {
            SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
            try
            {
                var notificationContext = notificationContextFactory();

                var monitorScope = new ApplicationMonitorScope(notificationContext);
                try
                {
                    Assert.AreSame(notificationContext, monitorScope.NotificationContext);
                    Assert.AreSame(monitorScope, ApplicationMonitorScope.Current);

                    await action(monitorScope);
                }
                finally
                {
                    await monitorScope.Dispose();
                }
            }
            finally
            {
                SynchronizationContext.SetSynchronizationContext(null);
            }
        }
コード例 #2
0
        public static void Main()
        {
            var app = new App();

            app.DispatcherUnhandledException += App_DispatcherUnhandledException;
            app.InitializeComponent();

            var applicationMonitorScope = new ApplicationMonitorScope(new WpfNotificationContext(app.Dispatcher));

            try
            {
                app.Run();
            }
            finally
            {
                applicationMonitorScope.Dispose()?.GetAwaiter().GetResult();
            }
        }
コード例 #3
0
        static void Main()
        {
#if DEBUG
            EventListener.OperationalEvent += (_, e) => Debug.WriteLine(e.ToDebugMessage());
#endif

            var app = new App();
            app.InitializeComponent();

            var applicationMonitorScope = new ApplicationMonitorScope(new WpfNotificationContext(app.Dispatcher));
            try
            {
                app.Run();
            }
            finally
            {
                applicationMonitorScope.Dispose().GetAwaiter().GetResult();
            }
        }