public ActionResult RunNow(int id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageScheduleTasks))
                return AccessDeniedView();

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

                var task = new Task(scheduleTask);
                //ensure that the task is enabled
                task.Enabled = true;
                //do not dispose. otherwise, we can get exception that DbContext is disposed
                task.Execute(true, false, false);
                SuccessNotification(_localizationService.GetResource("Admin.System.ScheduleTasks.RunNow.Done"));
            }
            catch (Exception exc)
            {
                ErrorNotification(exc);
            }

            return RedirectToAction("List");
        }
 private void ExecuteTask(Task task)
 {
     try
     {
         // set the task to enabled so it will run
         task.Enabled = true;
         task.Execute(true, false, true); // do not dispose - otherwise we can get an exception that DbContext is disposed, only run on one instance of a web farm
         SuccessNotification(string.Format(_localizationService.GetResource("Plugins.Misc.QixolPromo.RunScheduleTask.Done"), task.Name));
     }
     catch (Exception e)
     {
         ErrorNotification(e);
     }
 }