Beispiel #1
0
 public async Task OnShutdown()
 {
     Working = false;
     if (timerTask != null)
     {
         await timerTask;
     }
     await StateComponent.SaveAllState();
 }
Beispiel #2
0
 public Task SaveAllStates()
 {
     return(StateComponent.SaveAllState());
 }
Beispiel #3
0
        async Task timerLoop()
        {
            var random    = new System.Random();
            int onceDelta = 1000;
            int delayTime = 0;
            int saveTime  = random.Next(Settings.Ins.DataFlushTimeMin, Settings.Ins.DataFlushTimeMax);

            while (delayTime < saveTime * 1000)
            {
                //不能一次性delay,退出程序时监听不到
                await Task.Delay(onceDelta);

                delayTime += onceDelta;
                if (!Working)
                {
                    break;
                }
            }

            while (Working)
            {
                var start = DateTime.Now;

                await StateComponent.TimerSave();

                var delta = DateTime.Now - start;
                LOGGER.Info("db timer save state time:{}毫秒", delta.TotalMilliseconds);
                if (!Working)
                {
                    break;
                }

                await ActorManager.CheckIdle();

                delta = DateTime.Now - start;
                LOGGER.Info("db timer loop time:{}毫秒", delta.TotalMilliseconds);

                if (!Working)
                {
                    break;
                }

                int delay = 10000;
                if (delta.TotalSeconds < saveTime)
                {
                    delay = (saveTime - (int)delta.TotalSeconds) * 1000;
                }

                delayTime = 0;
                while (delayTime < delay)
                {
                    await Task.Delay(onceDelta);

                    delayTime += onceDelta;
                    if (!Working)
                    {
                        break;
                    }
                }
            }
            LOGGER.Info("exit db timer loop...");
        }