/// <summary> /// this method is called when something is neede to perform on UI-Thread. This method must be called /// only within the Lock method /// </summary> /// <param name="Method">Which method should be performed on UIThread.</param> /// <param name="Arguments">arguments for the Mmethod.</param> public void RunOnUIThread(Delegate Method, params object[] Arguments) { Debug.WriteLine("RunOnUIThread, locking lock2"); Monitor.Enter(this.lock2); Debug.WriteLine("RunOnUIThread, releasing lock1"); Monitor.Exit(this.lock1); this.lock1Locked = false; Debug.WriteLine("RunOnUIThread, creating waiting operation"); WaitingOperation waitingOperation = this._uiThreadWaitingOperation = new WaitingOperation(Method, Arguments); if (IsThisCallOnUIThread()) { Debug.WriteLine("RunOnUIThread, I am on UIThread now"); waitingOperation.DoOperation(); } else { BeginInvokeOnUIThread(new MethodInvoker(waitingOperation.DoOperation)); } Debug.WriteLine("RunOnUIThread, releasing lock2"); Monitor.Exit(this.lock2); Debug.WriteLine("RunOnUIThread, waiting to async operation to complete"); waitingOperation.CompletedEvent.WaitOne(); Debug.WriteLine("RunOnUIThread EXIT"); }
/// <summary> /// This method is used to synchronize calls on AutomationElementTreeNode instance. /// </summary> public IDisposable Lock() { Debug.WriteLine("SyncManager.Lock, locking lock1"); Monitor.Enter(lock1); //if this call is made on UIThread then try to complete UIThread waiting operation if (IsThisCallOnUIThread()) { Debug.WriteLine("SyncManager.Lock, waiting for lock2"); lock (lock2) //this lock is used to wait until waiting operation is created { Debug.WriteLine("SyncManager.Lock, got lock2!"); if (this._uiThreadWaitingOperation != null) { Debug.WriteLine("\nSyncManager.Lock, WOW, going to do waiting job!\n"); this._uiThreadWaitingOperation.DoOperation(); this._uiThreadWaitingOperation = null; } } } Debug.WriteLine("SyncManager.Lock, locking workLock"); Monitor.Enter(workLock); lock1Locked = true; return(new LockDisposer(this)); }
public Proc Delay(WaitingOperation waitionOp) { if (!CSP.Inst) { Debug.LogError("UniKH/CSP/Proc: delay proc failed, CSP are not loaded."); } if (isActive) { Debug.LogError("UniKH/CSP/Proc: delay proc failed, this proc is currently running."); } if (GetOpCurr() != null) { Debug.LogError( "UniKH/CSP/Proc: delay proc failed, delay object are already set. Maybe you can use QueueJumping to achieve similar effects."); } m_opCurr = waitionOp; m_opCurr.SetStartTimeMS(CSP.Inst.sw.ElapsedMilliseconds); return(this); }
/// <summary> /// this method is called when something is neede to perform on UI-Thread. This method must be called /// only within the Lock method /// </summary> /// <param name="Method">Which method should be performed on UIThread.</param> /// <param name="Arguments">arguments for the Mmethod.</param> public void RunOnUIThread(Delegate Method, params object[] Arguments) { Debug.WriteLine("RunOnUIThread, locking lock2"); Monitor.Enter(this.lock2); Debug.WriteLine("RunOnUIThread, releasing lock1"); Monitor.Exit(this.lock1); this.lock1Locked = false; Debug.WriteLine("RunOnUIThread, creating waiting operation"); WaitingOperation waitingOperation = this._uiThreadWaitingOperation = new WaitingOperation(Method, Arguments); if (IsThisCallOnUIThread()) { Debug.WriteLine("RunOnUIThread, I am on UIThread now"); waitingOperation.DoOperation(); } else BeginInvokeOnUIThread(new MethodInvoker(waitingOperation.DoOperation)); Debug.WriteLine("RunOnUIThread, releasing lock2"); Monitor.Exit(this.lock2); Debug.WriteLine("RunOnUIThread, waiting to async operation to complete"); waitingOperation.CompletedEvent.WaitOne(); Debug.WriteLine("RunOnUIThread EXIT"); }
/// <summary> /// This method is used to synchronize calls on AutomationElementTreeNode instance. /// </summary> public IDisposable Lock() { Debug.WriteLine("SyncManager.Lock, locking lock1"); Monitor.Enter(lock1); //if this call is made on UIThread then try to complete UIThread waiting operation if (IsThisCallOnUIThread()) { Debug.WriteLine("SyncManager.Lock, waiting for lock2"); lock (lock2) //this lock is used to wait until waiting operation is created { Debug.WriteLine("SyncManager.Lock, got lock2!"); if (this._uiThreadWaitingOperation != null) { Debug.WriteLine("\nSyncManager.Lock, WOW, going to do waiting job!\n"); this._uiThreadWaitingOperation.DoOperation(); this._uiThreadWaitingOperation = null; } } } Debug.WriteLine("SyncManager.Lock, locking workLock"); Monitor.Enter(workLock); lock1Locked = true; return new LockDisposer(this); }
public WaitingOperation SetOpCurr(WaitingOperation op) { op.SetStartTimeMS(ExecutedTime); return(m_opCurr = op); }