| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 
 |  
                //List of Tasks
                List<Task<object>> lstTasks = new List<Task<object>>();
 
                // Will start to search on selected promary Sites
                foreach (SCCMSite site in lbSccmSites.SelectedItems)
                {
 
                    SCCMSite tmpSite = site;
 
                    Task<object> tsk = new Task<object>(() =>
                     {
                         PageExecutionJob.JbList.AddJob(tmpSite.Name, "Connection to WMI Database");
 
                         //Search for the Advertisement Name (have to select the site name in the query to retreive only advertisements belonging to this site)
                         Dictionary<string, string> dCriteria = new Dictionary<string, string>();
                         dCriteria.Add("%" + sAdvSearched + "%", SCCMField.ATTRIBUT_NAME_ADVERTISEMENT_NAME);
                         dCriteria.Add(tmpSite.Name, SCCMField.ATTRIBUT_NAME_ADVERTISEMENT_SOURCE_SITE);
 
                         List<SCCMAdvertisement> lAdvFoundOnSite = new List<SCCMAdvertisement>();
 
						 //EXCEPTION CAN HAPPEN HERE.
                             lAdvFoundOnSite = SCCMAdvertisement.GetAdvertisementByPropertyLike(dCriteria, site);
                             lAdvFound.AddRange(lAdvFoundOnSite);
 
                             //Pass the result information retreived for the bwLastGenerated.RunWorkerCompleted event
                             List<object> lstResult = new List<object>();
                             lstResult.Add(tmpSite.Name);
                             lstResult.Add(lAdvFoundOnSite.Count);
                             lstResult.Add(Job.JobStatusValue.DoneSuccessfully);
                             lstResult.Add(lAdvFoundOnSite);
 
                             return lstResult;
 
                     });
                    tsk.ContinueWith((t) =>
                    {
                        if (t.Status == TaskStatus.RanToCompletion)
                        {
                            List<object> lstResult = t.Result as List<object>;
 
                            PageExecutionJob.JbList.UpdateJob(lstResult[0].ToString(), lstResult[1] + " Advertisement(s) found on " + lstResult[0], (Job.JobStatusValue)lstResult[2]);
                            dgSCCM.BindSCCMAdvertisements((List<SCCMAdvertisement>)lstResult[3]);
                        }
                    }, TaskContinuationOptions.OnlyOnRanToCompletion);
                    tsk.ContinueWith((t) =>
                    {
                        PageExecutionJob.JbList.UpdateJob(tmpSite.Name, " Error retreiving Advertisement(s) : " + t.Exception.Message, Job.JobStatusValue.DoneError);
                    }, TaskContinuationOptions.OnlyOnFaulted);
 
                   lstTasks.Add(tsk);
                   tsk.Start();
 
                } | 
Partager