private void DoWork(Job job)
        {
            job.ReportVerboseMessage("Starting Work");
            job.ReportProgress(0 , "Starting Work");

            for (int i = 1; i <= 100; i++)
            {
                //check for cancel
                if (job.CancellationToken.IsCancellationRequested)
                {

                    job.ReportVerboseMessage("Cancellation Completed");
                    return;
                }

                job.ReportVerboseMessage(string.Format("Starting Work on {0}", i));
                System.Threading.Thread.Sleep(1000);
                for (int j = 0; j < 10; j++)
                {
                    job.ReportVerboseMessage(string.Format("{0} - {1}", i, j));
                    System.Threading.Thread.Sleep(100);
                }
                job.ReportVerboseMessage(string.Format("Finsihed Work on {0}", i));
                decimal percentComplete = (int)Math.Round((double)(100 * i) / 100);
                job.ReportProgress((int)percentComplete, string.Format("Completed Work on {0}", i));
                System.Threading.Thread.Sleep(100);
            }

                job.ReportVerboseMessage("Finished Work");
            System.Threading.Thread.Sleep(1000);
        }
        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;
     job.VerboseReport += HandleJobVerboseMessage;
 }