Well, I have to admit I don’t know whether “ForceReparseTextAsync” is reasonable. I have no idea why it fails for me. Seems to be related to the way we run our application - we use a thread per ribbon form, so that modal dialogs are only model to the form they were opened from. But even with a similar approach, I could not reproduce the locks.
But I noticed something: when I initialize my code editor in the real application, the initialization code including “ForceReparseText” is called twice. And the second call causes this exception:
System.OperationCanceledException
HResult=0x8013153B
Message=The operation was canceled.
Source=System.Private.CoreLib
StackTrace:
at System.Threading.CancellationToken.ThrowOperationCanceledException()
at Microsoft.CodeAnalysis.Classification.AbstractSyntaxClassificationService.Worker.ClassifyNode(SyntaxNode syntax)
at Microsoft.CodeAnalysis.Classification.AbstractSyntaxClassificationService.Worker.ProcessNodes()
at Microsoft.CodeAnalysis.Classification.AbstractSyntaxClassificationService.Worker.Classify(SemanticModel semanticModel, TextSpan textSpan, ArrayBuilder`1 list, Func`2 getNodeClassifiers, Func`2 getTokenClassifiers, ClassificationOptions options, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Classification.AbstractSyntaxClassificationService.AddSemanticClassifications(SemanticModel semanticModel, TextSpan textSpan, Func`2 getNodeClassifiers, Func`2 getTokenClassifiers, ArrayBuilder`1 result, ClassificationOptions options, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Classification.Classifier.GetClassifiedSpans(HostWorkspaceServices workspaceServices, SemanticModel semanticModel, TextSpan textSpan, ClassificationOptions options, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Classification.Classifier.<GetClassifiedSpansAsync>d__0.MoveNext()
at Alternet.Syntax.Parsers.Roslyn.RoslynParser.Tokenizer.<ParsedAsync>d__10.MoveNext()
at Alternet.Syntax.Parsers.Roslyn.RoslynParser.<ParseSyntaxAsync>d__50.MoveNext()
at HG.Tools.Guiwin.AlternetWrapper.VBMethodParser.<ParseSyntaxAsync>d__18.MoveNext() in E:\...VBSnippetParser.cs:line 529
This exception was originally thrown at this call stack:
System.Threading.CancellationToken.ThrowOperationCanceledException()
Microsoft.CodeAnalysis.Classification.AbstractSyntaxClassificationService.Worker.ClassifyNode(Microsoft.CodeAnalysis.SyntaxNode)
Microsoft.CodeAnalysis.Classification.AbstractSyntaxClassificationService.Worker.ProcessNodes()
Microsoft.CodeAnalysis.Classification.AbstractSyntaxClassificationService.Worker.Classify(Microsoft.CodeAnalysis.SemanticModel, Microsoft.CodeAnalysis.Text.TextSpan, Microsoft.CodeAnalysis.PooledObjects.ArrayBuilder<Microsoft.CodeAnalysis.Classification.ClassifiedSpan>, System.Func<Microsoft.CodeAnalysis.SyntaxNode, System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Classification.Classifiers.ISyntaxClassifier>>, System.Func<Microsoft.CodeAnalysis.SyntaxToken, System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Classification.Classifiers.ISyntaxClassifier>>, Microsoft.CodeAnalysis.Classification.ClassificationOptions, System.Threading.CancellationToken)
Microsoft.CodeAnalysis.Classification.AbstractSyntaxClassificationService.AddSemanticClassifications(Microsoft.CodeAnalysis.SemanticModel, Microsoft.CodeAnalysis.Text.TextSpan, System.Func<Microsoft.CodeAnalysis.SyntaxNode, System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Classification.Classifiers.ISyntaxClassifier>>, System.Func<Microsoft.CodeAnalysis.SyntaxToken, System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Classification.Classifiers.ISyntaxClassifier>>, Microsoft.CodeAnalysis.PooledObjects.ArrayBuilder<Microsoft.CodeAnalysis.Classification.ClassifiedSpan>, Microsoft.CodeAnalysis.Classification.ClassificationOptions, System.Threading.CancellationToken)
Microsoft.CodeAnalysis.Classification.Classifier.GetClassifiedSpans(Microsoft.CodeAnalysis.Host.HostWorkspaceServices, Microsoft.CodeAnalysis.SemanticModel, Microsoft.CodeAnalysis.Text.TextSpan, Microsoft.CodeAnalysis.Classification.ClassificationOptions, System.Threading.CancellationToken)
Microsoft.CodeAnalysis.Classification.Classifier.GetClassifiedSpansAsync(Microsoft.CodeAnalysis.Document, Microsoft.CodeAnalysis.Text.TextSpan, System.Threading.CancellationToken)
Alternet.Syntax.Parsers.Roslyn.RoslynParser.Tokenizer.ParsedAsync(Microsoft.CodeAnalysis.Document, int, int, System.Threading.CancellationToken)
Alternet.Syntax.Parsers.Roslyn.RoslynParser.ParseSyntaxAsync(Microsoft.CodeAnalysis.Document, int, int, System.Threading.CancellationToken)
HG.Tools.Guiwin.AlternetWrapper.VBMethodParser.ParseSyntaxAsync(Microsoft.CodeAnalysis.Document, int, int, System.Threading.CancellationToken) in VBSnippetParser.cs
If I remove the second call, then the lock does not occur and the editor opens fine.
Maybe something is in an invalid state due to the cancel error? But I also could not reproduce this with your sample.
All this async/await is off my head I fear…
Best regards
Wolfgang