public void Invoke(Action action)
{
// Execute now if already on the thread
if (Thread.CurrentThread == _thread)
{
action();
}
else
{
lock (action)
{
// Schedule action
InvokeLater(action);
// Wait for action to complete
ThreadMonitor.Wait(action);
}
}
}