public void Update() { if (this.InvokeRequired) { throw new InvalidOperationException(); } lock (SyncPadLock) { if (this.syncItem != null) { this.syncItem.MethodResult = this.syncItem.Method.DynamicInvoke(this.syncItem.MethodArgs); this.syncItem.CompletedSynchronously = true; this.syncItem.IsCompleted = true; } Monitor.Pulse(SyncPadLock); } lock (AsyncPadLock) { while (this.asyncQueue.Count > 0) { InvokeHelperItem ihi = this.asyncQueue.Dequeue(); ihi.MethodResult = ihi.Method.DynamicInvoke(ihi.MethodArgs); ihi.CompletedSynchronously = false; ihi.IsCompleted = true; } Monitor.Pulse(AsyncPadLock); } }
public IAsyncResult BeginInvoke(Delegate method, object[] args) { var retValue = new InvokeHelperItem(method, args); lock (AsyncPadLock) { this.asyncQueue.Enqueue(retValue); } return(retValue); }
public object Invoke(Delegate method, object[] args) { object retValue; lock (SyncPadLock) { if (!this.InvokeRequired) { return(method.DynamicInvoke(args)); } this.syncItem = new InvokeHelperItem(method, args); Monitor.Wait(SyncPadLock); retValue = this.syncItem.MethodResult; this.syncItem = null; } return(retValue); }