I have a solution / projects based studio where I have (custom)SourceFile objects encapsulating an (actipro)EditorDocument. When I want to edit a file I use an (actipro)SyntaxEditor and I bind its Document property to the (actipro)EditorDocument of the (custom)SourceFile associated with the file. Each change in the (actipro)SyntaxEditor is reflected in the (actipro)EditorDocument.CurrentSnapshot in the (custom)SourceFile.
This works perfectly but problems arises when I want to use the (custom)SourceFile independently from an (actipro)SyntaxEditor, AFTER it has been bound once to an (actipro)SyntaxEditor. In refactoring scenario I need to modify the underlying (actipro)EditorDocument.Text and it happens in another thread. As soon as I want to use the SetText method I have this exception :
System.InvalidOperationException : calling thread cannot access this object because another thread is proprietary
System.InvalidOperationException : calling thread cannot access this object because another thread is proprietary System.Windows.Threading.Dispatcher.VerifyAccess() à System.Windows.Threading.DispatcherObject.VerifyAccess() à System.Windows.DependencyObject.GetValue(DependencyProperty dp) à ActiproSoftware.Windows.Controls.SyntaxEditor.SyntaxEditor.get_IsMultiLine() à ActiproSoftware.Windows.Controls.SyntaxEditor.SyntaxEditor.OnDocumentTextChanging(Object sender, TextSnapshotChangingEventArgs e) à System.EventHandler'1.Invoke(Object sender, TEventArgs e) à ActiproSoftware.Text.Implementation.TextDocumentBase.OnTextChanging(TextSnapshotChangingEventArgs e) à ActiproSoftware.Text.Implementation.TextDocumentBase.#O7c(#g7b textChange) à #Q2b.#g7b.Apply() à ActiproSoftware.Text.Implementation.TextDocumentBase.SetText(String text)
I understand the SyntaxEditor is bound to the TextChanging property of my (actipro)EditorDocument but :
- I need to use the same (actipro)EditorDocument also in another thread;
- I need to be able to use it while the (actipro)SyntaxEditor might be open;
- I want to reuse the same (actipro)EditorDocument and I don't want to be obliged to provide the (actipro)SyntaxEditor a new one because I would be obligated to bind a lot of stuff such as text changes, language, external changes, etc...
Thank you for your suggestions.