Example #1
0
 private void SafeWrapCallback(Action action)
 {
     // This method will try to catch exceptions so that they don't bubble up to our
     // callers. However, ThreadAbortExceptions will continue to bubble up.
     try {
         CurrentThread = Thread.CurrentThread;
         ISyncContextLock syncContextLock = null;
         try {
             syncContextLock = (_syncContext != null) ? _syncContext.Enter() : null;
             try {
                 action();
             }
             catch (Exception ex) {
                 Error = ExceptionDispatchInfo.Capture(ex);
             }
         }
         finally {
             if (syncContextLock != null)
             {
                 syncContextLock.Leave();
             }
         }
     }
     finally {
         CurrentThread = null;
         ChangeOperationCount(-1);
     }
 }