private void RunMainTask(object parameter) { SwitchStatus(); var installMode = (bool)((object[])parameter)[0]; var items = (IList <NgenFileItem>)((object[])parameter)[1]; var previousStatus = new NgenFileStatus[items.Count]; for (var i = 0; i < items.Count; i++) { var file = items[i]; previousStatus[i] = file.Status; file.Status = NgenFileStatus.Pending; } var processedFiles = 0; Parallel.For(0, items.Count, (currentIndex, state) => { if (Status == AppStatus.Stopping) { state.Stop(); } var file = items[currentIndex]; file.Status = NgenFileStatus.InProgress; var ngen = new NgenProcess(file.AssemblyDetails); var installed = ngen.Check(); if (installMode && !installed) { ngen.Install(); installed = ngen.Check(); } else if (!installMode && installed) { ngen.Uninstall(); installed = ngen.Check(); } file.Status = installed ? NgenFileStatus.Installed : NgenFileStatus.Deinstalled; lock (Locker) { processedFiles++; OnProgressChanged(processedFiles, FileList.Count); } } ); for (var i = 0; i < items.Count; i++) { if (items[i].Status == NgenFileStatus.Pending) { items[i].Status = previousStatus[i]; } } SwitchStatus(); }
private void CheckFiles(IEnumerable <string> files) { var startIndex = FileList.Count; foreach (var file in files) { if (Status == AppStatus.Stopping) { return; } if (FileList.Any(item => file.ToLower() == item.AssemblyDetails.AssemblyFile.ToLower())) { continue; } var assembly = AssemblyDetails.FromFile(file); if (assembly == null) { continue; } FileList.Add(new NgenFileItem(assembly, NgenFileStatus.Unknown)); } var processedFiles = 0; Parallel.For(startIndex, FileList.Count, i => { var file = FileList[i]; if (Status == AppStatus.Stopping) { return; } file.Status = NgenFileStatus.InProgress; var ngen = new NgenProcess(file.AssemblyDetails); file.Status = ngen.Check() ? NgenFileStatus.Installed : NgenFileStatus.Deinstalled; lock (Locker) { processedFiles++; OnProgressChanged(processedFiles, FileList.Count); } }); }