private static void GameThread() { Thread.CurrentThread.Priority = ThreadPriority.Highest; long balance = 0L; GameMgr.m_clearGamesTimer = TickHelper.GetTickCount(); while (GameMgr.m_running) { long start = TickHelper.GetTickCount(); int gameCount = 0; try { gameCount = GameMgr.UpdateGames(start); if (GameMgr.m_clearGamesTimer <= start) { GameMgr.m_clearGamesTimer += (long)GameMgr.CLEAR_GAME_INTERVAL; ArrayList temp = new ArrayList(); foreach (BaseGame g in GameMgr.m_games) { if (g.GameState == eGameState.Stopped) { temp.Add(g); } } foreach (BaseGame g in temp) { GameMgr.m_games.Remove(g); } ThreadPool.QueueUserWorkItem(new WaitCallback(GameMgr.ClearStoppedGames), temp); } } catch (Exception ex) { GameMgr.log.Error("Game Mgr Thread Error:", ex); } long end = TickHelper.GetTickCount(); balance += GameMgr.THREAD_INTERVAL - (end - start); if (end - start > GameMgr.THREAD_INTERVAL * 2L) { GameMgr.log.WarnFormat("Game Mgr spent too much times: {0} ms, count:{1}", end - start, gameCount); } if (balance > 0L) { Thread.Sleep((int)balance); balance = 0L; } else { if (balance < -1000L) { balance += 1000L; } } if (GameMgr.DELAY_TIME > 0) { GameMgr.log.ErrorFormat("Delay for {0} ms!", GameMgr.DELAY_TIME); Thread.Sleep(GameMgr.DELAY_TIME); } } }
private static void GameThread() { Thread.CurrentThread.Priority = ThreadPriority.Highest; long num = 0L; GameMgr.m_clearGamesTimer = TickHelper.GetTickCount(); while (GameMgr.m_running) { long tickCount = TickHelper.GetTickCount(); int num2 = 0; try { num2 = GameMgr.UpdateGames(tickCount); if (GameMgr.m_clearGamesTimer <= tickCount) { GameMgr.m_clearGamesTimer += (long)GameMgr.CLEAR_GAME_INTERVAL; ArrayList arrayList = new ArrayList(); foreach (BaseGame current in GameMgr.m_games) { if (current.GameState == eGameState.Stopped) { arrayList.Add(current); } } foreach (BaseGame item in arrayList) { GameMgr.m_games.Remove(item); } ThreadPool.QueueUserWorkItem(new WaitCallback(GameMgr.ClearStoppedGames), arrayList); } } catch (Exception exception) { GameMgr.log.Error("Game Mgr Thread Error:", exception); } long tickCount2 = TickHelper.GetTickCount(); num += GameMgr.THREAD_INTERVAL - (tickCount2 - tickCount); if (tickCount2 - tickCount > GameMgr.THREAD_INTERVAL * 2L) { GameMgr.log.WarnFormat("Game Mgr spent too much times: {0} ms, count:{1}", tickCount2 - tickCount, num2); } if (num > 0L) { Thread.Sleep((int)num); num = 0L; } else { if (num < -1000L) { num += 1000L; } } } }