Example #1
0
        public void cancel()
        {
            TimerTask task = this.m_task;

            this.setTask((TimerTask)null);
            task?.cancel();
        }
Example #2
0
 public Timer()
 {
     this.m_task        = (TimerTask)null;
     this.m_delay       = 0;
     this.m_period      = 0;
     this.m_isFixedRate = false;
 }
    //精力计时完成
    protected void JingLiCalEnd(TimerTask task)
    {
        if (player.totalJingli > player.RTData.curJingLi)
        {
            player.RTData.curJingLi += 1;
            if (lab_Energy != null)
            {
                lab_Energy.SafeText(player.curJingLi.ToString() + "/" + player.totalJingli.ToString());

                float res = (float)player.curJingLi / (float)player.totalJingli;
                if (energySlider != null)
                {
                    energySlider.value = res;
                }
            }
        }
//		Debug.LogWarning ("  jing li  end    total jingli = " + player.totalJingli + " cur  jingli " + player.RTData.curJingLi);
        if (player.totalJingli > player.RTData.curJingLi)
        {
            long nNow = Core.TimerEng.curTime;

            TimerTask MonaTask = new TimerTask(nNow, nNow + player.RTData.unixTimeForJingLi, 1, ThreadType.MainThread);
            MonaTask.taskId      = TaskID.CalJingLi;
            MonaTask.onEventEnd += JingLiCalEnd;
            MonaTask.onEvent    += JingliMinus;
            MonaTask.DispatchToRealHandler();
        }
    }
Example #4
0
    void OnDayChanged(TimerTask tTask)
    {
        ///
        /// 新手引导的时候不能执行
        ///
        if (Core.Data.guideManger.isGuiding)
        {
            return;
        }

        HttpTask task = new HttpTask(ThreadType.MainThread, TaskResponse.Default_Response);

        task.AppendCommonParam(RequestType.MESSAGE_INFORMATION, new PlayerIDParam(Core.Data.playerManager.PlayerID, 100));
        task.afterCompleted = (BaseHttpRequest request, BaseResponse response) => {
            recordDayChanged(Core.Data.playerManager.RTData.systemTime);

            ///
            /// -------- 弹出提醒用户签到 --------
            ///
            if (CurScenesName == SceneName.MAINUI)
            {
                string content = Core.Data.stringManager.getString(55);
                string btn     = Core.Data.stringManager.getString(5030);
                UIInformation.GetInstance().SetInformation(content, btn, DBUIController.mDBUIInstance.SyncBackToMainUI, DBUIController.mDBUIInstance.SyncBackToMainUI);
            }
        };
        task.ErrorOccured = (BaseHttpRequest request, string error) => { ConsoleEx.DebugLog("SendFightRequest is error!"); };
        task.DispatchToRealHandler();
    }
Example #5
0
 //线程安全
 public void deleteTask(TimerTask task)
 {
     if (task != null && taskList != null)
     {
         taskList.Remove(task);
     }
 }
Example #6
0
 void EndTimeHandleQphD(TimerTask task)
 {
     if (_UISecretShop != null)
     {
         _UISecretShop.Back_OnClick();
     }
 }
Example #7
0
 /// <summary>
 /// Dispatchs to timer. Multi-thread safe.
 /// </summary>
 /// <param name="task">Task. If task equals Null, we will ignore it.</param>
 public void dispatchToTimer(TimerTask task)
 {
     if (task != null && taskList != null)
     {
         taskList.Add(task);
     }
 }
Example #8
0
    /// <summary>
    /// 开始记录下,第二天凌晨12点的时间。防止有部分用户会在晚上玩游戏之后不关闭游戏,导致服务器状态和客户端状态不一致
    /// 与此同时,也记录下当天晚上9点的时间。
    /// </summary>
    public void recordDayChanged(long sysTime)
    {
        //
        //------ 当天结束 -------
        //
        long LeftOfDayEnd = DateHelper.getLeftTimingbeforeDayChanged(sysTime);

        ConsoleEx.DebugLog("Start to recording Day Changed.. leaving seconds = " + LeftOfDayEnd, ConsoleEx.YELLOW);
        long      now  = Core.TimerEng.curTime;
        TimerTask task = new TimerTask(now, now + LeftOfDayEnd, 1);

        task.onEventEnd = OnDayChanged;
        task.DispatchToRealHandler();


        //
        // ------ 当天晚上9点 -------
        //
        long LeftOfNineNight = DateHelper.getNineNight(sysTime);

        ConsoleEx.DebugLog("Start to recording 21:00.. leaving seconds = " + LeftOfNineNight, ConsoleEx.YELLOW);
        if (LeftOfNineNight > 0)
        {
            TimerTask task2 = new TimerTask(now, now + LeftOfNineNight, 1);
            task2.onEventEnd = OnNineChanged;
            task2.DispatchToRealHandler();
        }
    }
Example #9
0
        void checkClientStatus(TimerTask task)
        {
            long now = stopwatch.ElapsedMilliseconds;

            //申请读锁
            readerWriterLock.EnterReadLock();
            int dis = 0;

            foreach (VirtualClient client in ClientPool.Values)
            {
                long delta = now - client.HeartTick;
                if (delta > Timeout)
                {
                    client.curStatus = client.curStatus.set(ClientStatus.Timeout);
                    dis += 1;
                    //TODO : 超时了,还算有效的链接吗,
                    //需要 ConnectedClientCount -=1 & ReadyClientCount -= 1 吗?
                }
                else
                {
                    client.curStatus = client.curStatus.clear(ClientStatus.Timeout);
                }
            }

            //释放读锁
            readerWriterLock.ExitReadLock();

            DisConnectedCount = dis;
        }
 public PTimer(PTimerManager manager, TimerTask task)
 {
     m_manager = manager;
     m_manager.AddTimer(this);
     m_task = task;
     m_timeRemainingInSeconds = m_intervalInSeconds;
 }
    //召唤结束后 清空 时间 回调 等
    public void CallDragonTimeCompleted(TimerTask timerTask)
    {
        if (timerTask.taskId == TaskID.CallEarthDragonTimer)
        {
            Core.Data.dragonManager.callEarthDragonTimeCompletedDelegate = null;
            Core.Data.dragonManager.callEarthDragonTime = 0;
            this.callDragonTime = 0;
            Core.Data.dragonManager.DragonList[(int)DragonManager.DragonType.EarthDragon].RTData.st = 0;
            Core.Data.dragonManager.callDragonSucceed[(int)DragonManager.DragonType.EarthDragon]    = true;
            this.callDragonCompletedTaskID[(int)DragonManager.DragonType.EarthDragon] = timerTask.taskId;
        }
        else if (timerTask.taskId == TaskID.CallNMKXDragonTimer)
        {
            Core.Data.dragonManager.callNMKXDragonTimeCompletedDelegate = null;
            Core.Data.dragonManager.callNMKXDragonTime = 0;
            this.callDragonTime = 0;
            Core.Data.dragonManager.DragonList[(int)DragonManager.DragonType.NMKXDragon].RTData.st = 0;
            Core.Data.dragonManager.callDragonSucceed[(int)DragonManager.DragonType.NMKXDragon]    = true;
            this.callDragonCompletedTaskID[(int)DragonManager.DragonType.NMKXDragon] = timerTask.taskId;
        }
        showCallDragonTime();

//        Debug.Log(" check call dragon succeed in CallDragonTimeCompleteddddddddddddddddddddddddddddd");

        if (Application.loadedLevelName != "GameUI")
        {
            return;
        }

        checkCallDragonSucceed();
    }
Example #12
0
        protected void CleanUp(string testFolder = DefaultRuntimeFolder)
        {
            Console.WriteLine("Cleaning up test.");

            if (TimerTask != null)
            {
                TestTimer.Stop();
                TimerTask.Dispose();
                TimerTask = null;
            }

            // Wait for file upload task to complete
            Thread.Sleep(500);

            string dir = Path.Combine(Directory.GetCurrentDirectory(), testFolder);

            try
            {
                if (Directory.Exists(dir))
                {
                    Directory.Delete(dir, true);
                }
            }
            catch (IOException)
            {
                // do not fail if clean up is unsuccessful
            }
        }
Example #13
0
        public IActionResult Remove(Guid id)
        {
            using (var db = new AllInOneContext.AllInOneContext())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        TimerTask delObj = db.TimerTask.FirstOrDefault(t => t.TimerTaskId.Equals(id));
                        if (delObj == null || !delObj.PlanId.Equals(id))
                        {
                            return(NotFound());
                        }
                        db.TimerTask.Remove(delObj);
                        db.SaveChanges();
                        transaction.Commit();

                        //移除任务服务器的预案
                        string url             = string.Format("{0}/Task/PlanAction/{1}", GlobalSetting.TaskServerBaseUrl, id);
                        string responseContent = "";
                        HttpClientHelper.Delete(url, ref responseContent);
                        return(NoContent());
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        _logger.LogError("删除定时任务异常,Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace);
                        return(BadRequest(ex));
                    }
                }
            }
        }
Example #14
0
    public TimerTask AddTimerTask(Action ac, float interval)
    {
        var task = new TimerTask(ac, interval);

        mTimerTaskList.Add(task);
        return(task);
    }
Example #15
0
 public IActionResult Add([FromBody] TimerTask task)
 {
     if (task == null)
     {
         return(BadRequest());
     }
     using (var db = new AllInOneContext.AllInOneContext())
     {
         try
         {
             //计算预案的下一执行时间
             db.TimerTask.Add(task);
             db.SaveChanges();
             //将预案发送到任务服务器
             string url = string.Format("{0}/Task/PlanAction", GlobalSetting.TaskServerBaseUrl);
             HttpClientHelper.Post <TimerTask>(task, url);
             return(CreatedAtAction("", task));
         }
         catch (Exception ex)
         {
             _logger.LogError("新增定时任务异常,Message:{0}\r\nStackTrace{1}", ex.Message, ex.StackTrace);
             return(BadRequest(ex));
         }
     }
 }
Example #16
0
        public IActionResult Update([FromBody] TimerTask task)
        {
            if (task == null)
            {
                return(BadRequest("TimerTask object is null!"));
            }

            using (var db = new AllInOneContext.AllInOneContext())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        db.TimerTask.Update(task);
                        transaction.Commit();
                        return(NoContent());
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        _logger.LogError("更新定时任务异常,Message:{0}\r\nStackTrace{1}", ex.Message, ex.StackTrace);
                        return(BadRequest(ex));
                    }
                }
            }
        }
Example #17
0
        public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
        {
            Task.Run(() => {
                try
                {
                    PowerManager pm          = (PowerManager)GetSystemService(Context.PowerService);
                    PowerManager.WakeLock wl = pm.NewWakeLock(WakeLockFlags.Partial, "My Tag");
                    wl.Acquire();
                    var counter = new TimerTask();
                    counter.RunTimer(_cts, startId).Wait();
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    if (_cts.IsCancellationRequested)
                    {
                        var message = new CancelledMessage();
                        //Device.BeginInvokeOnMainThread(
                        //    () => MessagingCenter.Send(message, "CancelledMessage")
                        //);
                    }
                }
            }, _cts.Token);

            return(StartCommandResult.Sticky);
        }
Example #18
0
 /// <summary>
 /// start auto cycle. </summary>
 /// <param name="delay"> delay time </param>
 /// <param name="duration"> animation duration time. </param>
 /// <param name="autoRecover"> if recover after user touches the slider. </param>
 public virtual void startAutoCycle(long delay, long duration, bool autoRecover)
 {
     if (mCycleTimer != null)
     {
         mCycleTimer.Cancel();
     }
     if (mCycleTask != null)
     {
         mCycleTask.Cancel();
     }
     if (mResumingTask != null)
     {
         mResumingTask.Cancel();
     }
     if (mResumingTimer != null)
     {
         mResumingTimer.Cancel();
     }
     mSliderDuration = duration;
     mCycleTimer     = new Timer();
     mAutoRecover    = autoRecover;
     mCycleTask      = new TimerTaskAnonymousInnerClassHelper(this);
     mCycleTimer.Schedule(mCycleTask, delay, mSliderDuration);
     mCycling   = true;
     mAutoCycle = true;
 }
Example #19
0
 public void RemoveTimerTask(TimerTask task)
 {
     if (mTimerTaskList.Contains(task))
     {
         mTimerTaskList.Remove(task);
     }
 }
Example #20
0
    public void startMianZhanTimer(long startTime, long endTime)
    {
        TimerTask task = new TimerTask(startTime, endTime, 1);

        task.taskId = TaskID.DragonMianZhanTimer;

        task.onEventEnd += mianZhanTimeCompleted;

        this.mianZhanTime = endTime - startTime;
        this.mianZhanTime = this.mianZhanTime <= 0 ? 0 : this.mianZhanTime;

        if (this.mianZhanTimerEvent != null)
        {
            this.mianZhanTimerEvent(this.mianZhanTime);
        }

        task.onEvent += (TimerTask t) =>
        {
            if (task.taskId == TaskID.DragonMianZhanTimer)
            {
                this.mianZhanTime = t.leftTime;
                if (this.mianZhanTimerEvent != null)
                {
                    this.mianZhanTimerEvent(this.mianZhanTime);
                }
            }
        };
        task.DispatchToRealHandler();
    }
Example #21
0
 public PTimer(PTimerManager manager, TimerTask task)
 {
     m_manager = manager;
     m_manager.AddTimer(this);
     m_task = task;
     m_timeRemainingInSeconds = m_intervalInSeconds;
 }
Example #22
0
    void OnTimer(TimerTask task)
    {
        int pron = -1;

        foreach (KeyValuePair <int, int> itor in m_dicTimer)
        {
            if (itor.Value == task._Id)
            {
                pron = itor.Key;
                break;
            }
        }

        if (pron != -1)
        {
            if (m_dicZhaomuData.ContainsKey(pron))
            {
                ZhaoMuStateData state = m_dicZhaomuData [pron];
                state.coolTime = task.leftTime;
            }
            else
            {
                RED.LogWarning("zhaomu pron data not find   " + pron);
            }
        }
        else
        {
            RED.LogWarning("zhaomu timer task id not find   " + task._Id);
        }
    }
        /// <inheritdoc />
        public void Start(CancellationToken cancellationToken)
        {
            _logger.Information("Message Bus starting");

            if (_cancellationTokenSource != null)
            {
                throw new ArgumentException("Message Bus not Stopped");
            }

            _cancellationTokenSource       = new CancellationTokenSource();
            _cancellationTokenRegistration = cancellationToken.Register(Stop);

            SendHandshake();

            // ReSharper disable once InconsistentlySynchronizedField
            foreach (var subscribeHandler in _subscribeHandlers)
            {
                subscribeHandler.Start(_cancellationTokenSource.Token, SyncMode);
            }

            // ReSharper disable once InconsistentlySynchronizedField
            foreach (var requestHandler in _requestHandlers)
            {
                requestHandler.Start(_cancellationTokenSource.Token, SyncMode);
            }

            _handshakeTask = new TimerTask();

            if (!SyncMode)
            {
                _handshakeTask.Start(SendHandshake, 30000, _cancellationTokenSource.Token);
            }

            _logger.Information("Message Bus started");
        }
Example #24
0
 protected void Application_Start(object sender, EventArgs e)
 {
     //CMSEmergencySystem.Email.GetExcelFile.DataTable();
     //Controllers.EmailController.JobSchedule.Start();
     TimerTask tt = new TimerTask();
     //tt.initAllTimerTask();
 }
Example #25
0
        public void scheduleRepeated(TimerTask task, long period)
        {
            lock (this)
            {
                if (_instance == null)
                {
                    throw new Ice.CommunicatorDestroyedException();
                }

                Token token = new Token(Time.currentMonotonicTimeMillis() + period, ++_tokenId, period, task);

                try
                {
                    _tasks.Add(task, token);
                    _tokens.Add(token, null);
                }
                catch (System.ArgumentException)
                {
                    Debug.Assert(false);
                }

                if (token.scheduledTime < _wakeUpTime)
                {
                    Monitor.Pulse(this);
                }
            }
        }
Example #26
0
        protected void CleanUp(string testFolder = DefaultRuntimeFolder)
        {
            Logger.Log(Level.Verbose, "Cleaning up test.");

            if (_enableRealtimeLogUpload)
            {
                if (TimerTask != null)
                {
                    TestTimer.Stop();
                    TimerTask.Dispose();
                    TimerTask = null;
                }

                // Wait for file upload task to complete
                Thread.Sleep(500);
            }

            string dir = Path.Combine(Directory.GetCurrentDirectory(), testFolder);

            try
            {
                if (Directory.Exists(dir))
                {
                    Directory.Delete(dir, true);
                }
            }
            catch (IOException)
            {
                // do not fail if clean up is unsuccessful
            }
            catch (UnauthorizedAccessException)
            {
                // do not fail if clean up is unsuccessful
            }
        }
Example #27
0
 Token(long scheduledTime, int id, long delay, TimerTask task)
 {
     this.scheduledTime = scheduledTime;
     this.id            = id;
     this.delay         = delay;
     this.task          = task;
 }
Example #28
0
        /// <summary>
        /// Called from <see cref="Handle.Stop"/> to remove a task from the queue.
        /// </summary>
        /// <param name="taskObj"></param>
        /// <param name="evt"></param>
        private void ForceStopFromHandle(object taskObj, TimerEvent evt)
        {
            TimerTask task = (taskObj as TimerTask);

            this.tasks[(int)evt].Remove(task);
            this.taskHandleMapping.Remove(task.handle);
        }
Example #29
0
        public ActionResult AddTask(TimerTask timerTask, string email)
        {
            try
            {
                var      destPath = Server.MapPath("~/XmlDataBase/Timerdb.xml");
                XElement root     = XElement.Load(destPath);

                IEnumerable <XElement> xElement = root.Elements();
                if (xElement != null)
                {
                    var test = xElement.FirstOrDefault(x =>
                    {
                        var element = x.Element("Email");
                        return(element != null && element.Value == email);
                    });
                    test?.Add(new XElement("AddedTask",
                                           new XElement("NameofTask", timerTask.NameOfTask),
                                           new XElement("Description", timerTask.Description),
                                           new XElement("ElaspedTime", timerTask.Timer)
                                           ));
                }
                root.Save(destPath);
                return(RedirectToAction("CounterView", new { id = timerTask.Timer }));
            }
            catch (Exception ex)
            {
                TempData["status"] = "error";
                TempData["msg"]    = ex.InnerException;
                return(View());
            }
        }
Example #30
0
    void StartTimer(ZhaoMuStateData state)
    {
        if (m_dicZhaomuData.ContainsKey(state.pron))
        {
            m_dicZhaomuData [state.pron] = state;
        }
        else
        {
            m_dicZhaomuData.Add(state.pron, state);
        }

        if (m_dicTimer.ContainsKey(state.pron))
        {
            Core.TimerEng.deleteTask(m_dicTimer [state.pron]);
            m_dicTimer.Remove(state.pron);
        }

        long curTime = Core.TimerEng.curTime;

        if (state.coolTime > 0)
        {
            TimerTask task = new TimerTask(curTime, curTime + state.coolTime, 1, ThreadType.MainThread);
            task.onEventEnd = OnTimeEnd;
            task.onEvent    = OnTimer;
            task.DispatchToRealHandler();

            m_dicTimer.Add(state.pron, task._Id);
        }
    }
Example #31
0
 public static void StopTimerTask(TimerTask timerTask)
 {
     if (_RunningTimerTaskList.Contains(timerTask))
     {
         timerTask.bTaskRunning = false;
         _RunningTimerTaskList.Remove(timerTask);
     }
 }
 public void Schedule(IThreadRunnable task, long delay)
 {
     Timer timer = new Timer();
     TimerTask task2 = new TimerTask(this, timer, task);
     timer.Elapsed += new ElapsedEventHandler(task2.OnTimedEvent);
     timer.AutoReset = false;
     timer.Interval = (delay < 1L) ? ((double) 1L) : ((double) delay);
     lock (this)
     {
         this._timers.Add(timer);
     }
     timer.Start();
 }
Example #33
0
File: Timer.cs Project: externl/ice
        public bool cancel(TimerTask task)
        {
            lock(this)
            {
                if(_instance == null)
                {
                    return false;
                }

                Token token;
                if(!_tasks.TryGetValue(task, out token))
                {
                    return false;
                }
                _tasks.Remove(task);
                _tokens.Remove(token);
                return true;
            }
        }
        protected void debugTimerTestThread()
        {
            // create set (timer task). initially empty
            TimerTask timerTask = new TimerTask("ShortTimers");

            Console.WriteLine("Start timers " + DateTime.Now);

            // create two types of timers
            TimerList timers_5sec = new TimerList("5sec", 5 * 1000, 100, this.Timer5sHandler, timerTask);
            TimerList timers_30sec = new TimerList("30sec", 30 * 1000, 100, this.Timer30sHandler, timerTask);

            timerTask.Start();

            // start some timers
            timers_5sec.Start();
            timers_5sec.Start();
            timers_5sec.Start();
            Thread.Sleep(1 * 1000);
            timers_5sec.Start();

            ITimer timer;
            long timerId;
            timers_30sec.Start(out timer, out timerId, null, false);
            timers_5sec.Start();

            debugTimerShowCallback(null, null, null);

            // wait for the first timer to expire
            Thread.Sleep(10 * 1000);
            timers_30sec.Stop(timer, timerId);

            Thread.Sleep(30 * 1000);
            debugTimerShowCallback(null, null, null);

            // clean up
            timers_5sec.Dispose();
            timers_30sec.Dispose();
            timerTask.Dispose();
        }
 public void AddTimerTask(TimerTask task)
 {
     lock (this.dicTimerContent)
     {
         if (this.dicTimerContent.ContainsKey(task.Name))
         {
             this.dicTimerContent.Remove(task.Name);
         }
         this.dicTimerContent.Add(task.Name, task);
     }
 }
Example #36
0
 public PTimer(PTimerManager manager, TimerTask task)
 {
     m_manager = manager;
     m_manager.AddTimer(this);
     m_task = task;
 }
Example #37
0
 public void Schedule(TimerTask field98257B, long l, long l1)
 {
     throw new System.NotImplementedException();
 }
		public void RenewTimer()
		{
			if (null != timer)
				timer.Cancel ();
			timer_task = new MyTimerTask2 (this);
			timer = new Timer ();
			timer.Schedule (timer_task, SCREEN_ON_TIMEOUT_MS);

		}
Example #39
0
File: Timer.cs Project: externl/ice
        public void scheduleRepeated(TimerTask task, long period)
        {
            lock(this)
            {
                if(_instance == null)
                {
                    throw new Ice.CommunicatorDestroyedException();
                }

                Token token = new Token(Time.currentMonotonicTimeMillis() + period, ++_tokenId, period, task);

                try
                {
                    _tasks.Add(task, token);
                    _tokens.Add(token, null);
                }
                catch(System.ArgumentException)
                {
                    Debug.Assert(false);
                }

                if(token.scheduledTime < _wakeUpTime)
                {
                    System.Threading.Monitor.Pulse(this);
                }
            }
        }
Example #40
0
File: Timer.cs Project: externl/ice
 public Token(long scheduledTime, int id, long delay, TimerTask task)
 {
     this.scheduledTime = scheduledTime;
     this.id = id;
     this.delay = delay;
     this.task = task;
 }