Exemplo n.º 1
0
        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;
            }
        }
Exemplo n.º 2
0
        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;
            }
        }
Exemplo n.º 3
0
 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);
     }
 }
Exemplo n.º 4
0
 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);
     }
 }
Exemplo n.º 5
0
 public void EnqueTask(CancellableTask task)
 {
     this._tasks.Add(task);
     task.Start();
 }
Exemplo n.º 6
0
 public void EnqueTask(CancellableTask task)
 {
     this._tasks.Add(task);
     task.Start();
 }