protected override void StartService() { try { lock (_taskFactory) { if (null == _currentTask) { _currentTask = new CancellableTask(_taskFactory(_cancellationTokenSource.Token), _cancellationTokenSource); _currentTask.Task.Start(); } } } catch (Exception ex) { _log.FatalException(String.Format("Service {0} - Unexpected Error - Failed to start", ServiceName), ex); if (null != _currentTask) { _currentTask.Cancel(); _currentTask = null; } //make sure that Windows knows that we're not running -- with the service messed, we can't throw; } }
protected override void StartService() { try { lock (_taskFactory) { if (null == _currentTask) { _currentTask = new CancellableTask(_taskFactory(_cancellationTokenSource.Token), _cancellationTokenSource); _currentTask.Task.Start(); } } } catch (Exception ex) { _log.FatalException(String.Format("Service {0} - Unexpected Error - Failed to start", ServiceName), ex); if (null != _currentTask) { _currentTask.Cancel(); _currentTask = null; } //make sure that Windows knows that we're not running -- with the service messed, we can't throw; } }
private void RunTaskImpl() { try { Stopwatch timer = new Stopwatch(); timer.Start(); _log.Debug(() => string.Format("Service {0} - starting task at {1}", ServiceName, DateTime.Now)); var token = new CancellationTokenSource(); var task = new CancellableTask(_taskFactory(token.Token), token); _taskPoolManager.EnqueTask(task); task.Task.Wait(); timer.Stop(); _log.Debug(() => String.Format("Service {0} - task completed at {1} - elapsed time {2}", ServiceName, DateTime.Now, timer.Elapsed)); } catch (Exception ex) { _log.ErrorException(String.Format("Service {0} - Unexpected Error - couldn't start task", ServiceName), ex); } }
private void RunTaskImpl() { try { Stopwatch timer = new Stopwatch(); timer.Start(); _log.Debug(() => string.Format("Service {0} - starting task at {1}", ServiceName, DateTime.Now)); var token = new CancellationTokenSource(); var task = new CancellableTask(_taskFactory(token.Token), token); _taskPoolManager.EnqueTask(task); task.Task.Wait(); timer.Stop(); _log.Debug(() => String.Format("Service {0} - task completed at {1} - elapsed time {2}", ServiceName, DateTime.Now, timer.Elapsed)); } catch (Exception ex) { _log.ErrorException(String.Format("Service {0} - Unexpected Error - couldn't start task", ServiceName), ex); } }
public void EnqueTask(CancellableTask task) { this._tasks.Add(task); task.Start(); }
public void EnqueTask(CancellableTask task) { this._tasks.Add(task); task.Start(); }