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; }
private void BroadcastJobStatus(Job job) { job.ProgressChanged += HandleJobProgressChanged; job.Completed += HandleJobCompleted; }