private void ScheduleJobChekVpnAll(IListProcessor blist, IList selectedItems, bool all, bool favoritOnly) { blist.StartRefreshing(); // create background tasks, which nevertheless are executed sequentially // it would be possible to create one background thread and perform all the tasks sequentially, // but at the same time the opportunity to destroy the hanging task is lost and to let the others continue // todo worth thinking about limiting the number of waiting threads //prepare task list IList list = null; if (all) { list = Dm.Instance.FindAll(typeof(JVPNServer)); } else if (favoritOnly) { IList list0 = Dm.Instance.FindAll(typeof(JVPNServer)); list = new List <JVPNServer>(); foreach (var n in list0) { JVPNServer m = (JVPNServer)n; if (m.Favorite) { list.Add(m); } } } else { list = selectedItems; } if (list == null || list.Count == 0) { throw new Exception("No items to test found"); } //check for allready running tasks and stop it bool foundWorking = false; foreach (var n in list) { JVPNServer m = (JVPNServer)n; if (m.JRunningJob != null && m.JRunningJob.JJobType != null && m.JRunningJob.IsWorking()) { foundWorking = true; break; } } if (foundWorking) { DialogResult res = MessageBox.Show(VpnSelectorLibRes.Running_job_found__They_will_be_aborted_or_press__Cancel__to_exit, FrwConstants.WARNING, MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (res == DialogResult.Cancel) { return; } } foreach (var n in list) { JVPNServer m = (JVPNServer)n; if (favoritOnly == false || m.Favorite) { if (m.JRunningJob != null) { if (m.JRunningJob.JJobType != null) { if (m.JRunningJob.IsWorking()) { JobManager.Instance.AbortJob(m.JRunningJob); } else { //m.JRunningJob.Stage = RunningJobStageEnum.initial.ToString(); //Dm.Instance.SaveObject(m.JRunningJob); } } m.JRunningJob = null; Dm.Instance.SaveObject(m); } } } //Schedule tasks foreach (var n in list) { JVPNServer m = (JVPNServer)n; ScheduleJobChekVpnServer(m); JobManager.ScheduleJobToQueue(m.JRunningJob); currQueueJobType = m.JRunningJob.JJobType; } if (currQueueJobType != null) { currQueueJobType.RemoveAllPostJobBatchEventHandlers(); currQueueJobType.PostJobBatch += currQueueJobType.StandartPostLJobBatchEventHandler; JobManager.StartProcessingJobBatch(currQueueJobType); } }