public IAsyncResult BeginInvoke(Delegate method, object[] args) { if (method == null) throw new ArgumentNullException(); var invoke = new MessageLoopInvoke(method, args ?? new object[0]); invokes.Enqueue(invoke); return invoke; }
public object Invoke(Delegate method, object[] args) { if (method == null) throw new ArgumentNullException(); var invoke = new MessageLoopInvoke(method, args ?? new object[0]); invokes.Enqueue(invoke); invoke.WaitHandle.WaitOne(); if (invoke.Exception != null) throw new MessageLoopException(invoke.Exception); return invoke.Result; }