public bool TransactionAvailable() { // if we are on the original thread, just call straight thru. if (this.originalThread == System.Threading.Thread.CurrentThread) { return(originalCommandRuntime.TransactionAvailable()); } // 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(); bool result = false; // set the function to run runOnMainThread = () => result = originalCommandRuntime.TransactionAvailable(); // tell the main thread to go ahead readyToRun.Set(); // wait for the result (or cancellation!) WaitForCompletion(); // set the output variables return(result); } catch (System.OperationCanceledException exception) { // maybe don't even worry? throw exception; } }