public void Queue <T>(long yieldingInterval, ExecuteYieldingDelegate <T> executeYieldingDelegate, T item) { YieldingController yieldingController; if (SyncContext == null) { yieldingController = new YieldingController(0); while (!executeYieldingDelegate.Invoke(item, yieldingController)) { // Loop till delegate tells us that is has been finished } return; } yieldingController = new YieldingController(yieldingInterval); SyncContext.Post(ExecuteYieldingDelegate, new Object[] { executeYieldingDelegate, yieldingController, item }); }
protected void ExecuteYieldingDelegate(Object state) { Object[] stateArray = (Object[])state; Delegate executeYieldingDelegate = (Delegate)stateArray[0]; YieldingController yieldingController = (YieldingController)stateArray[1]; Object item = stateArray[2]; // Calculate time when the delegate should yield its action yieldingController.CalculateNextInterval(); if ((bool)executeYieldingDelegate.DynamicInvoke(item, yieldingController)) { // Execution finished by decision of the delegate return; } // Re-queue action in the UI events SyncContext.Post(ExecuteYieldingDelegate, state); }