private void _timer_Elapsed(object sender, ElapsedEventArgs e) { DontStopAsync dtAsync = WorkerAsync; Task.Factory.StartNew(dtAsync.Invoke, _cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current) .ConfigureAwait(false); }
protected override void OnStart(string[] args) { _timer.Enabled = true; _timer.Interval = _timerInterval; _timer.Elapsed += _timer_Elapsed; if (args == null || !args.Contains("immediate")) { return; } DontStopAsync dtAsync = WorkerAsync; Task.Factory.StartNew(dtAsync.Invoke, _cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current) .ConfigureAwait(false); }