internal void Initialize2(IProgressMonitor progressMonitor) { if (!initializing) { return; } try { IProjectContent[] referencedContents; lock (this.ReferencedContents) { referencedContents = new IProjectContent[this.ReferencedContents.Count]; this.ReferencedContents.CopyTo(referencedContents, 0); } foreach (IProjectContent referencedContent in referencedContents) { if (referencedContent is ReflectionProjectContent) { ((ReflectionProjectContent)referencedContent).InitializeReferences(referencedContents); } } ParseableFileContentFinder finder = new ParseableFileContentFinder(); var fileContents = ( from p in project.Items.AsParallel().WithCancellation(progressMonitor.CancellationToken) where !ItemType.NonFileItemTypes.Contains(p.ItemType) && !String.IsNullOrEmpty(p.FileName) select FileName.Create(p.FileName) ).ToList(); object progressLock = new object(); double fileCountInverse = 1.0 / fileContents.Count; Parallel.ForEach( fileContents, new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount * 2, CancellationToken = progressMonitor.CancellationToken }, fileName => { // Don't read files we don't have a parser for. // This avoids loading huge files (e.g. sdps) when we have no intention of parsing them. if (ParserService.GetParser(fileName) != null) { ITextBuffer content = finder.Create(fileName); if (content != null) { ParserService.ParseFile(this, fileName, content); } } lock (progressLock) { progressMonitor.Progress += fileCountInverse; } } ); } finally { initializing = false; progressMonitor.Progress = 1; } }
internal void Initialize2(IProgressMonitor progressMonitor) { if (!initializing) { return; } int progressStart = progressMonitor.WorkDone; ParseableFileContentEnumerator enumerator = new ParseableFileContentEnumerator(project); try { progressMonitor.TaskName = "${res:ICSharpCode.SharpDevelop.Internal.ParserService.Parsing} " + project.Name + "..."; IProjectContent[] referencedContents; lock (this.ReferencedContents) { referencedContents = new IProjectContent[this.ReferencedContents.Count]; this.ReferencedContents.CopyTo(referencedContents, 0); } foreach (IProjectContent referencedContent in referencedContents) { if (referencedContent is ReflectionProjectContent) { ((ReflectionProjectContent)referencedContent).InitializeReferences(); } } while (enumerator.MoveNext()) { int i = enumerator.Index; if ((i % 5) == 2) { progressMonitor.WorkDone = progressStart + i; } ParserService.ParseFile(this, enumerator.CurrentFileName, enumerator.CurrentFileContent, true); if (!initializing) { return; } } } finally { initializing = false; progressMonitor.WorkDone = progressStart + enumerator.ItemCount; enumerator.Dispose(); } }