コード例 #1
0
        public void ThrowTerminatingError(ErrorRecord errorRecord)
        {
            // if we are on the original thread, just call straight thru.
            if (this.originalThread == System.Threading.Thread.CurrentThread)
            {
                originalCommandRuntime.ThrowTerminatingError(errorRecord);
                return;
            }

            // otherwise, queue up the request and wait for the main thread to do the right thing.
            try
            {
                // wait for our turn to talk to the main thread
                WaitOurTurn();

                // set the function to run
                runOnMainThread = () => originalCommandRuntime.ThrowTerminatingError(errorRecord);

                // tell the main thread to go ahead
                readyToRun.Set();

                // wait for the result (or cancellation!)
                WaitForCompletion();

                // return
                return;
            }
            catch (System.OperationCanceledException exception)
            {
                // maybe don't even worry?
                throw exception;
            }
        }