Ejemplo n.º 1
0
        void _timer_Tick(object sender, EventArgs e)
        {
            #region очистка старых данных
            var now = DateTime.Now;
            var dd  = now.Day;
            var hh  = now.Hour;
            var mm  = now.Minute;
            if (_lastMinute == mm)
            {
                return;
            }
            _lastMinute = mm;
            if (_lastHour == hh)
            {
                return;
            }
            _lastHour = hh;
            if (_lastDay == dd)
            {
                return;
            }
            _lastDay       = dd;
            _timer.Enabled = false;
            ThreadPool.QueueUserWorkItem(arg =>
            {
                // очистка накоплений
                if (Data.DeleteLogsAfter > 0)
                {
                    Data.DeleteFromLogs(now.AddDays(-Data.DeleteLogsAfter));
                }
                if (Data.DeleteTrendsAfter > 0)
                {
                    Data.DeleteFromTrends(now.AddDays(-Data.DeleteTrendsAfter));
                }

                var method = new MethodInvoker(() =>
                {
                    _timer.Enabled = true;
                });
                if (InvokeRequired)
                {
                    BeginInvoke(method);
                }
                else
                {
                    method();
                }
            });

            #endregion
        }