public ActionResult RunJob(int id, string returnUrl = "")
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageScheduleTasks))
                return AccessDeniedView();

            returnUrl = returnUrl.NullEmpty() ?? Request.UrlReferrer.ToString();

            var t = AsyncRunner.Run(c =>
            {
                try
                {
                    var svc = c.Resolve<IScheduleTaskService>();

                    var scheduleTask = svc.GetTaskById(id);
                    if (scheduleTask == null)
                        throw new Exception("Schedule task cannot be loaded");

                    var job = new Job(scheduleTask);
                    job.Enabled = true;
                    job.Execute(c, false);
                }
                catch
                {
                    try
                    {
                        _scheduleTaskService.EnsureTaskIsNotRunning(id);
                    }
                    catch (Exception) { }
                }
            });

            // wait only 100 ms.
            t.Wait(100);

            if (t.IsCompleted)
            {
                if (!t.IsFaulted)
                {
                    NotifySuccess(T("Admin.System.ScheduleTasks.RunNow.Completed"));
                }
                else
                {
                    NotifyError(t.Exception.Flatten().InnerException);
                }
            }
            else
            {
                NotifyInfo(T("Admin.System.ScheduleTasks.RunNow.Progress"));
            }

            return Redirect(returnUrl);
        }
		public bool RunScheduleTask()
		{
			if (ScheduleTask.IsRunning)
			{
				Notifier.Information(GetProgressInfo());
				return true;
			}

			string scheduleTaskType = ScheduleTaskType;

			var task = AsyncRunner.Run((container, ct) =>
			{
				int taskId = 0;
				try
				{
					var svc = container.Resolve<IScheduleTaskService>();

					var scheduleTask = svc.GetTaskByType(scheduleTaskType);

					if (scheduleTask == null)
						throw new Exception("Schedule task cannot be loaded");

					taskId = scheduleTask.Id;

					var job = new Job(scheduleTask);
					job.Enabled = true;
					job.Execute(ct, container, false);
				}
				catch (Exception)
				{
					_scheduleTaskService.EnsureTaskIsNotRunning(taskId);
				}
			}, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);

			task.Wait(100);

			if (task.IsCompleted)
			{
				if (!task.IsFaulted)
				{
					Notifier.Success(GetResource("Admin.System.ScheduleTasks.RunNow.Completed"));
				}
				else
				{
					var exc = task.Exception.Flatten().InnerException;
					Notifier.Error(exc.Message);
					Logger.Error(exc.Message, exc);					
				}
			}
			else
			{
				Notifier.Information(GetResource("Admin.System.ScheduleTasks.RunNow.Progress"));
				return true;
			}
			return false;
		}