示例#1
0
        public Job DoJobAsync(Action<Job> action)
        {
            var job = new Job(Guid.NewGuid().ToString());

            // this will (should!) never fail, because job.Id is globally unique
            _runningJobs.TryAdd(job.Id, job);

            Task.Factory.StartNew(() =>
            {
                action(job);
                job.ReportComplete();
                _runningJobs.TryRemove(job.Id, out job);
            }, 
            TaskCreationOptions.LongRunning);

            BroadcastJobStatus(job);

            return job;
        }
示例#2
0
 private void BroadcastJobStatus(Job job)
 {
     job.ProgressChanged += HandleJobProgressChanged;
     job.Completed += HandleJobCompleted;
 }