示例#1
0
        public static void RunSync(Action a)
        {
            if (isUnitTestingMode)
            {
                a();
                return;
            }
            Exception exn = null;

            Debug.Assert(ctxt != null, "The SynchronizationContext must be captured before calling this method");
            // Send on UI thread will execute immediately.
#pragma warning disable VSTHRD001 // Avoid legacy thread switching APIs
            ctxt.Send(ignore =>
#pragma warning restore VSTHRD001 // Avoid legacy thread switching APIs
            {
                try
                {
                    UIThread.MustBeCalledFromUIThread();
                    a();
                }
                catch (Exception e)
                {
                    exn = e;
                }
            }, null
                      );
            if (exn != null)
            {
                // throw exception on calling thread, preserve stacktrace
                if (!exn.Data.Contains(WrappedStacktraceKey))
                {
                    exn.Data[WrappedStacktraceKey] = exn.StackTrace;
                }
                throw exn;
            }
        }
示例#2
0
 public static void Unregister(uint n)
 {
     UIThread.MustBeCalledFromUIThread();
     taskReporters.Remove(n);
 }