public static void StartBackgroundJob(MonitoredActivity activity, string title, string message, Action job, Handler handler)
        {
            // Make the progress dialog uncancelable, so that we can gurantee
            // the thread will be done before the activity getting destroyed.
            var dialog = ProgressDialog.Show(activity, title, message, true, false);

            ThreadPool.QueueUserWorkItem(w => new BackgroundJob(activity, job, dialog, handler).Run());
        }
        public BackgroundJob(MonitoredActivity activity, Action job, ProgressDialog progressDialog, Handler handler)
        {
            _activity       = activity;
            _progressDialog = progressDialog;
            _job            = job;
            _handler        = handler;

            _activity.Destroying += (sender, e) => {
                // We get here only when the onDestroyed being called before
                // the cleanupRunner. So, run it now and remove it from the queue
                CleanUp();
                handler.RemoveCallbacks(CleanUp);
            };

            _activity.Stopping += (sender, e) => progressDialog.Hide();
            _activity.Starting += (sender, e) => progressDialog.Show();
        }