void Dispatch () { DispatcherOperation[] ops; lock (queuedOperations) { ops = queuedOperations.ToArray (); queuedOperations.Clear (); pending = false; } foreach (DispatcherOperation op in ops) { op.Invoke (); } }