/// <summary>
        /// Registration method.  Call this from OnLaunched and OnActivated inside the App.xaml.cs
        /// </summary>
        /// <returns></returns>
        public static ExceptionHandlingSynchronizationContext Register()
        {
            var syncContext = Current;

            if (syncContext == null)
            {
                throw new InvalidOperationException("Ensure a synchronization context exists before calling this method.");
            }


            var customSynchronizationContext = syncContext as ExceptionHandlingSynchronizationContext;


            if (customSynchronizationContext == null)
            {
                customSynchronizationContext = new ExceptionHandlingSynchronizationContext(syncContext);
                SetSynchronizationContext(customSynchronizationContext);
            }


            return(customSynchronizationContext);
        }
コード例 #2
0
ファイル: App.xaml.cs プロジェクト: zephyrer/MarkDown.UWP
 /// <summary>
 /// Should be called from OnActivated and OnLaunched
 /// </summary>
 private void RegisterExceptionHandlingSynchronizationContext()
 {
     ExceptionHandlingSynchronizationContext
     .Register()
     .UnhandledException += SynchronizationContext_UnhandledException;
 }