From 1a1763410280f4c7a7ed6a26e14420d29eaa3bbd Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Mon, 13 Feb 2006 17:34:17 +0000 Subject: [PATCH] Fixed exception when QuickClassBrowserPanel panel was refreshing while a partial class was updated by the parser thread. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1143 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../ParserService/DefaultProjectContent.cs | 32 +++++++----- .../Gui/Editor/QuickClassBrowserPanel.cs | 52 ++++++++++--------- 2 files changed, 45 insertions(+), 39 deletions(-) diff --git a/src/Main/Base/Project/Src/Services/ParserService/DefaultProjectContent.cs b/src/Main/Base/Project/Src/Services/ParserService/DefaultProjectContent.cs index a555000aba..24c13ea348 100644 --- a/src/Main/Base/Project/Src/Services/ParserService/DefaultProjectContent.cs +++ b/src/Main/Base/Project/Src/Services/ParserService/DefaultProjectContent.cs @@ -300,16 +300,18 @@ namespace ICSharpCode.Core CompoundClass compound = GetClassInternal(fullyQualifiedName, addClass.TypeParameters.Count, language) as CompoundClass; if (compound != null) { // possibly replace existing class (look for CU with same filename) - for (int i = 0; i < compound.Parts.Count; i++) { - if (compound.Parts[i].CompilationUnit.FileName == addClass.CompilationUnit.FileName) { - compound.Parts[i] = addClass; - compound.UpdateInformationFromParts(); - LoggingService.Debug("Replaced old part!"); - return; + lock (compound) { + for (int i = 0; i < compound.Parts.Count; i++) { + if (compound.Parts[i].CompilationUnit.FileName == addClass.CompilationUnit.FileName) { + compound.Parts[i] = addClass; + compound.UpdateInformationFromParts(); + LoggingService.Debug("Replaced old part!"); + return; + } } + compound.Parts.Add(addClass); + compound.UpdateInformationFromParts(); } - compound.Parts.Add(addClass); - compound.UpdateInformationFromParts(); LoggingService.Debug("Added new part!"); return; } else { @@ -460,12 +462,14 @@ namespace ICSharpCode.Core // Use "as" cast to fix SD2-680: the stored class might be a part not marked as partial CompoundClass compound = GetClassInternal(fullyQualifiedName, @class.TypeParameters.Count, language) as CompoundClass; if (compound == null) return; - compound.Parts.Remove(@class); - if (compound.Parts.Count > 0) { - compound.UpdateInformationFromParts(); - return; - } else { - @class = compound; // all parts removed, remove compound class + lock (compound) { + compound.Parts.Remove(@class); + if (compound.Parts.Count > 0) { + compound.UpdateInformationFromParts(); + return; + } else { + @class = compound; // all parts removed, remove compound class + } } } diff --git a/src/Main/Base/Project/Src/TextEditor/Gui/Editor/QuickClassBrowserPanel.cs b/src/Main/Base/Project/Src/TextEditor/Gui/Editor/QuickClassBrowserPanel.cs index 2f043d148e..28187a5f57 100644 --- a/src/Main/Base/Project/Src/TextEditor/Gui/Editor/QuickClassBrowserPanel.cs +++ b/src/Main/Base/Project/Src/TextEditor/Gui/Editor/QuickClassBrowserPanel.cs @@ -345,32 +345,34 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor } } - int lastIndex = 0; - IComparer comparer = new Comparer(System.Globalization.CultureInfo.InvariantCulture); - - foreach (IMethod m in c.Methods) { - items.Add(new ComboBoxItem(m, m.Name, ClassBrowserIconService.GetIcon(m), partialMode ? currentPart.Methods.Contains(m) : true)); - } - items.Sort(lastIndex, c.Methods.Count, comparer); - lastIndex = items.Count; - - foreach (IProperty p in c.Properties) { - items.Add(new ComboBoxItem(p, p.Name, ClassBrowserIconService.GetIcon(p), partialMode ? currentPart.Properties.Contains(p) : true)); - } - items.Sort(lastIndex, c.Properties.Count, comparer); - lastIndex = items.Count; - - foreach (IField f in c.Fields) { - items.Add(new ComboBoxItem(f, f.Name, ClassBrowserIconService.GetIcon(f), partialMode ? currentPart.Fields.Contains(f) : true)); - } - items.Sort(lastIndex, c.Fields.Count, comparer); - lastIndex = items.Count; - - foreach (IEvent evt in c.Events) { - items.Add(new ComboBoxItem(evt, evt.Name, ClassBrowserIconService.GetIcon(evt), partialMode ? currentPart.Events.Contains(evt) : true)); + lock (c) { + int lastIndex = 0; + IComparer comparer = new Comparer(System.Globalization.CultureInfo.InvariantCulture); + + foreach (IMethod m in c.Methods) { + items.Add(new ComboBoxItem(m, m.Name, ClassBrowserIconService.GetIcon(m), partialMode ? currentPart.Methods.Contains(m) : true)); + } + items.Sort(lastIndex, c.Methods.Count, comparer); + lastIndex = items.Count; + + foreach (IProperty p in c.Properties) { + items.Add(new ComboBoxItem(p, p.Name, ClassBrowserIconService.GetIcon(p), partialMode ? currentPart.Properties.Contains(p) : true)); + } + items.Sort(lastIndex, c.Properties.Count, comparer); + lastIndex = items.Count; + + foreach (IField f in c.Fields) { + items.Add(new ComboBoxItem(f, f.Name, ClassBrowserIconService.GetIcon(f), partialMode ? currentPart.Fields.Contains(f) : true)); + } + items.Sort(lastIndex, c.Fields.Count, comparer); + lastIndex = items.Count; + + foreach (IEvent evt in c.Events) { + items.Add(new ComboBoxItem(evt, evt.Name, ClassBrowserIconService.GetIcon(evt), partialMode ? currentPart.Events.Contains(evt) : true)); + } + items.Sort(lastIndex, c.Events.Count, comparer); + lastIndex = items.Count; } - items.Sort(lastIndex, c.Events.Count, comparer); - lastIndex = items.Count; membersComboBox.BeginUpdate(); membersComboBox.Items.Clear();