private void RunGuardLoop() { int errorCount = 0; while (true) { lock (_ctsLock) { if (_cts == null) { LogInfo("NotStarted"); break; } if (_cts.IsCancellationRequested) { LogInfo("Cancelled"); break; } } try { LoopAction?.Invoke(); LoopTask?.Invoke().Wait(); } catch (Exception e) { errorCount++; if (errorCount > MaxTryFailCount) { LogInfo(string.Format("fail {0} more then max: {1}, exit", errorCount, MaxTryFailCount)); break; } LogEx(e, string.Format("fail time: {0}/{1}, ex:{2}", errorCount, MaxTryFailCount, e.Message)); } try { //Thread.Sleep actually makes current thread to sleep //Task.Delay is a logical delay without blocking the current thread. Task.Delay is a timer based wait mechanism. //In async programming model you should always use Task.Delay() if you want something(continuation) happen after some delay. TaskEx.Delay(LoopSpan).Wait(); } catch (TaskCanceledException) { //await TaskEx.Delay(LoopSpan); should enter here LogInfo(string.Format("Task Canceled => TaskCanceledException")); } catch (AggregateException) { //TaskEx.Delay(LoopSpan).Wait(); should enter here LogInfo(string.Format("Task Canceled => AggregateException")); } catch (Exception) { //should never enter here LogInfo(string.Format("Task Canceled => Exception")); } } }
/// <summary> /// Wait for message with requested type in 'this' queue /// </summary> /// <returns>first message in queue if it matches for request type. Null if exited by condition</returns> public T WaitForMessage(Type type, FinishCondition finish = null, LoopAction action = null) { while (true) { if (finish != null && finish()) { return(null); } if (action != null) { action.Execute(); } CloudQueueMessage startMsg = GetMessage(); if (startMsg == null) { System.Threading.Thread.Sleep(1000); continue; } DeleteMessage(startMsg); T message = ConvertMessage(startMsg); if (message.GetType() == type) { return(message); } } }
public void Add(int?item) { LoopAction loopAction = Add; if (!GameBoardLooper(item, loopAction)) { throw new ArgumentException("GameBoard Is full"); } }
public Action Handle() { LoopAction self = this; return(() => { self.action(); ScheduleManager.Schedule(self.time, self.Handle()); }); }
public static LoopAction NewObject() { GameObject pack = new GameObject { name = "Loop" }; LoopAction actionpack = pack.AddComponent <LoopAction>(); ActionPlayer player = pack.AddComponent <ActionPlayer>(); ActionList list = pack.AddComponent <ActionList>(); actionpack.PackPlayer = player; actionpack.PackActions = list; actionpack.name = "循环"; return(actionpack); }
private bool GameBoardLooper(int?item, LoopAction loopAction) { for (int x = 0; x < _gameBoardRoot; x++) { for (int y = 0; y < _gameBoardRoot; y++) { if (loopAction(item, x, y)) { return(true); } } } return(false); }
public void WaitForWorkers(int workersCount, MessageQueue <DispetcherMessage> dispatcherHandler, string sessionGuid, int sceneID, LoopAction action) { MessageQueue <RenderMessage> renderHandler = new MessageQueue <RenderMessage>(); for (int i = 0; i < workersCount; ++i) { IsFreeMessage isFreeMes = new IsFreeMessage(sessionGuid, sceneID); //send check message to worker renderHandler.AddMessage(isFreeMes); } int workersReadyCount = 0; while (workersReadyCount < workersCount) { DispetcherMessage dispMessage = dispatcherHandler.WaitForMessage(typeof(WorkerIsReady), null, action); ++workersReadyCount; } }
private void RunGuardLoop() { int errorCount = 0; while (true) { lock (_ctsLock) { if (_cts == null) { LogMessage("NotStarted"); break; } if (_cts.IsCancellationRequested) { LogMessage("Cancelled"); break; } } try { LoopAction?.Invoke(); LoopTask?.Invoke().Wait(); } catch (Exception e) { errorCount++; if (errorCount > MaxTryFailCount) { LogMessage(string.Format("fail {0} more then max: {1}, exit", errorCount, MaxTryFailCount)); break; } LogMessage(string.Format("fail time: {0}/{1}, ex:{2}", errorCount, MaxTryFailCount, e.Message)); } Task.Delay(LoopSpan).Wait(); } }
static unsafe ThreadWrapper() { s_pause = GetPauseDelegate(); }
public bool Remove(int?item) { LoopAction loopAction = Remove; return(GameBoardLooper(item, loopAction)); }
internal CombinatorialUtils(LoopAction loopAction) { this.loopAction = loopAction; }
/// <summary> /// Implementors should call this so the main loop has something /// to do. /// </summary> /// <param name="p_la">LoopAction method to run at each iteration</param> static public void SetAndStartAction(Control control, LoopAction p_la) { SetAction(control, p_la); Start(); }
public static void ScheduleInLoop(float timer, Action action) { LoopAction loop = new LoopAction(timer, action); Schedule(timer, loop.Handle()); }
static public void SetAction(Control control, LoopAction p_la) { LoopControl.control = control; control.Disposed += control_Disposed; loopAction = p_la; }
private static LoopAction loopAction; // our ptr to the function called in each frame iteration #endregion Fields #region Constructors /// <summary> /// Constructor sets Application.Idle handler /// </summary> static LoopControl() { loopAction = DefaultAction; fpsTimer = null; }
public static void Start() { Application.Idle += new EventHandler( Application_Idle ); loopAction = loopAction ?? DefaultAction; }
/// <summary> /// Implementors should call this so the main loop has something /// to do. /// </summary> /// <param name="p_la">LoopAction method to run at each iteration</param> public static void SetAndStartAction( Control control, LoopAction p_la ) { SetAction( control, p_la ); Start(); }
public bool Contains(int?item) { LoopAction loopAction = Contains; return(GameBoardLooper(item, loopAction)); }
public void WaitForMerger(MessageQueue <DispetcherMessage> dispatcherHandler, int sceneID, LoopAction action) { DispetcherMessage dispMessage = dispatcherHandler.WaitForMessage(typeof(MergerIsReady), null, action); MergerIsReady go = dispMessage as MergerIsReady; if (go.MergerQueueSuffix != sceneID.ToString()) //check for thread error { m_log.Error("Unknown error while waiting for 'MergerIsReady' message. ID: " + sceneID.ToString()); throw (new Exception("Unknown error while waiting for 'MergerIsReady' message")); } }
public static void Start() { Application.Idle += new EventHandler(Application_Idle); loopAction = loopAction ?? DefaultAction; }
/// <summary> /// Constructor sets Application.Idle handler /// </summary> static LoopControl() { loopAction = DefaultAction; fpsTimer = null; }
public static void AddLoop() { ActionPack newpack = LoopAction.NewObject(); Set2Object(newpack.gameObject); }
public static void SetAction( Control control, LoopAction p_la ) { LoopControl.control = control; control.Disposed += control_Disposed; loopAction = p_la; }