示例#1
0
        public void Start()
        {
            IBackgroundService backgroundService = (IBackgroundService)container.Resolve(type);

            backgroundService.RefreshSettings();

            //INFO: (erikpo) This check is just to make sure a value was provided for interval and that they can't put in an interval that will take down their server
            if (backgroundService.Interval.TotalSeconds > 10)
            {
#if DEBUG
                if (backgroundService.Enabled)
                {
                    backgroundService.Run();
                }
#endif

                isExecuting = false;

                timer = new Timer(
                    timerCallback,
                    null,
                    backgroundService.Interval,
                    new TimeSpan(0, 0, 0, 0, -1)
                    );
            }
        }
示例#2
0
        private void timerCallback(object state)
        {
            lock (timer)
            {
                IBackgroundService backgroundService = (IBackgroundService)container.Resolve(type);

                backgroundService.RefreshSettings();

                if (backgroundService.Enabled)
                {
                    //TODO: (erikpo) Instead of eating the exception, log it
                    try
                    {
                        backgroundService.Run();
                    }
                    catch
                    {
                    }
                }

                timer.Change(backgroundService.Interval, new TimeSpan(0, 0, 0, 0, -1));
            }

            //TODO: (erikpo) Once background services have a cancel state and timeout interval, check their state and cancel if appropriate
        }
示例#3
0
        protected override Task ExecuteAsync(CancellationToken stoppingToken)
        {
            Task.Run(async() =>
            {
                await _service.Run(stoppingToken);
            }, stoppingToken);

            return(Task.CompletedTask);
        }
示例#4
0
        public void Start()
        {
            lock (timer)
            {
                if (Status == BackgroundServiceExecutorStatus.Paused || Status == BackgroundServiceExecutorStatus.Stopped)
                {
                    if (Status == BackgroundServiceExecutorStatus.Stopped)
                    {
                        Status = BackgroundServiceExecutorStatus.Starting;

                        current = (IBackgroundService)container.Resolve(backgroundServiceType);
                        current.Initialize(moduleConfiguration);
                    }

                    Status = BackgroundServiceExecutorStatus.Running;

                    current.Run(moduleConfiguration);

                    timer.Change(interval, new TimeSpan(0, 0, 0, 0, -1));
                }
            }
        }
示例#5
0
        public void Start()
        {
            IBackgroundService backgroundService = (IBackgroundService)container.Resolve(type);
            IPlugin            plugin            = getPlugin();
            TimeSpan           interval          = getInterval(plugin);

            if (interval.TotalSeconds > 10)
            {
#if DEBUG
                if (plugin.Enabled)
                {
                    backgroundService.Run(plugin.Settings);
                }
#endif

                timer.Change(interval, new TimeSpan(0, 0, 0, 0, -1));
            }
        }
示例#6
0
        private void timerCallback(object state)
        {
            if (!isExecuting)
            {
                IBackgroundService backgroundService = (IBackgroundService)container.Resolve(type);

                backgroundService.RefreshSettings();

                if (backgroundService.Enabled)
                {
                    isExecuting = true;

                    backgroundService.Run();

                    isExecuting = false;
                }
            }

            //TODO: (erikpo) Once background services have a cancel state and timeout interval, check their state and cancel if appropriate
        }
示例#7
0
        private void timerCallback(object state)
        {
            lock (timer)
            {
                IBackgroundService backgroundService = (IBackgroundService)container.Resolve(type);
                IPlugin            plugin            = getPlugin();
                TimeSpan           interval          = getInterval(plugin);

                if (plugin.Enabled)
                {
                    try
                    {
                        backgroundService.Run(plugin.Settings);
                    }
                    catch
                    {
                    }
                }

                timer.Change(interval, new TimeSpan(0, 0, 0, 0, -1));
            }

            //TODO: (erikpo) Once background services have a cancel state and timeout interval, check their state and cancel if appropriate
        }