private void StartDynamicTimers()
        {
            var jobs = dynamicJobs.GetJobs();

            foreach (var x in jobs)
            {
                // 如果Hard Timer已经启动则注销实例
                if (JobTimers.ContainsKey(x.Id))
                {
                    JobTimers[x.Id].Dispose();
                    JobStatus[x.Id] = false;
                    JobTimers.Remove(x.Id);
                    JobStatus.Remove(x.Id);
                }
                int delta = Convert.ToInt32((x.Begin - DateTime.Now).TotalMilliseconds);
                if (delta < 0)
                {
                    delta = delta % x.Interval;
                    if (delta < 0)
                    {
                        delta += x.Interval;
                    }
                }
                Task.Factory.StartNew(() =>
                {
                    var timer = new Timer(t => {
                        Execute(x.Id);
                    }, null, delta, x.Interval);
                    JobTimers.Add(x.Id, timer);
                });
            }
        }
Exemple #2
0
        private void StartHardTimers()
        {
            foreach (var x in JobTypeCollection)
            {
                foreach (var y in x.DeclaredMethods)
                {
                    if (y.GetCustomAttribute <NonJobAttribute>() == null)
                    {
                        JobStatus.Add(x.FullName + '.' + y.Name, false);
                        var invoke = y.GetCustomAttribute <InvokeAttribute>();
                        if (invoke != null && invoke.IsEnabled)
                        {
                            long delta = 0;
                            if (invoke._begin == default(DateTime))
                            {
                                invoke._begin = DateTime.Now;
                            }
                            else
                            {
                                delta = Convert.ToInt64((invoke._begin - DateTime.Now).TotalMilliseconds.ToString("0"));
                            }
                            if (delta < 0)
                            {
                                delta = delta % Convert.ToInt64(invoke.Interval);
                                if (delta < 0)
                                {
                                    delta += Convert.ToInt64(invoke.Interval);
                                }
                            }

                            Task.Factory.StartNew(async() =>
                            {
                                if (delta > int.MaxValue)
                                {
                                    for (; delta > Int32.MaxValue; delta = delta - Int32.MaxValue)
                                    {
                                        await Task.Delay(Int32.MaxValue);
                                    }
                                }

                                var timer = new Timer(t => {
                                    Execute(x.FullName + '.' + y.Name);
                                }, null, Convert.ToInt32(delta), invoke.Interval);
                                JobTimers.Add(x.FullName + '.' + y.Name, timer);
                            });
                        }
                    }
                }
            }
        }
        public void RestartDynamicTimers()
        {
            var jobs = dynamicJobs.GetJobs();

            foreach (var x in jobs)
            {
                if (JobTimers.ContainsKey(x.Id))
                {
                    JobTimers[x.Id].Dispose();
                    JobStatus[x.Id] = false;
                    JobTimers.Remove(x.Id);
                    JobStatus.Remove(x.Id);
                }
            }
            StartDynamicTimers();
        }
Exemple #4
0
 private void StartHardTimers()
 {
     foreach (var x in JobTypeCollection)
     {
         foreach (var y in x.DeclaredMethods)
         {
             if (y.GetCustomAttribute <NonJobAttribute>() == null)
             {
                 JobStatus.Add(x.FullName + '.' + y.Name, false);
                 var invoke = y.GetCustomAttribute <InvokeAttribute>();
                 if (invoke != null && invoke.IsEnabled)
                 {
                     long delta = 0;
                     if (invoke._begin == default(DateTime))
                     {
                         invoke._begin = DateTime.Now;
                     }
                     else
                     {
                         delta = Convert.ToInt64((invoke._begin - DateTime.Now).TotalMilliseconds);
                     }
                     if (delta < 0)
                     {
                         delta = delta % invoke.Interval;
                         if (delta < 0)
                         {
                             delta += invoke.Interval;
                         }
                     }
                     Task.Factory.StartNew(() =>
                     {
                         var timer = new Timer(t =>
                         {
                             Execute(x.FullName + '.' + y.Name);
                         }, null, (int)delta, invoke.Interval);
                         JobTimers.Add(x.FullName + '.' + y.Name, timer);
                     });
                 }
             }
         }
     }
 }
Exemple #5
0
        private void StartDynamicTimers()
        {
            var jobs = dynamicJobs.GetJobs();

            foreach (var x in jobs)
            {
                // 如果Hard Timer已经启动则注销实例
                if (JobTimers.ContainsKey(x.Id))
                {
                    JobTimers[x.Id].Dispose();
                    JobStatus[x.Id] = false;
                    JobTimers.Remove(x.Id);
                    JobStatus.Remove(x.Id);
                }
                long delta = Convert.ToInt64((x.Begin - DateTime.Now).TotalMilliseconds);
                if (delta < 0)
                {
                    delta = delta % Convert.ToInt64(x.Interval);
                    if (delta < 0)
                    {
                        delta += Convert.ToInt64(x.Interval);
                    }
                }
                Task.Factory.StartNew(async() =>
                {
                    if (delta > int.MaxValue)
                    {
                        for (; delta > Int32.MaxValue; delta = delta - Int32.MaxValue)
                        {
                            await Task.Delay(Int32.MaxValue);
                        }
                    }
                    var timer = new Timer(t => {
                        Execute(x.Id);
                    }, null, Convert.ToInt32(delta), x.Interval);
                    JobTimers.Add(x.Id, timer);
                });
            }
        }