Accessing Document in Destructor

SyntaxEditor for WPF Forum

Posted 9 years ago by Martin de Jong - Statistics Netherlands
Version: 9.2.0514
Avatar
Hi

In my destructor i want to access the Document. This gives an exception "InvalidOperationException":
            try {
                // TODO solve... locking prob ?
                if (this.Document != null && !string.IsNullOrWhiteSpace(this.Document.FileName))
                    CachedErrors.Instance.RemoveFileItems(this.Document.FileName);
            } catch { }
What am i doing wrong?

BTW, Is the next version of the WPF Studio coming soon?

Regards

Martin

Comments (5)

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Martin,

The Document.FileName property just returns a field directly. I'm not thinking that exception comes from us. It probably is raised by the .NET framework itself.

The next WPF Studio version is probably still several weeks out. We're in the midst of doing big enhancements on a number of products for it.


Actipro Software Support

Posted 9 years ago by Martin de Jong - Statistics Netherlands
Avatar
Yes, it looks its caused by another thread:

[System.InvalidOperationException] {"The calling thread cannot access this object because a different thread owns it."}

Could it be the Background Parse thread? Have to find another solution anyway, i guess.

Martin
Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Martin,

Our worker threads for the parser are named so if you are debugging in VS and open the Threads tool window, if it's from our worker threads, their name will start with "ThreadedParseRequestDispatcher."

Then you need to look at the call stack to see what code is actually causing the exception. Even if it is in our thread, the code causing the problem may be in an event handler that you created. But that will at least help you find the source of the problem.

If you think it is caused by us or if you need more help, please make a simple sample project showing the issue and we'll be glad to help.


Actipro Software Support

Posted 9 years ago by Martin de Jong - Statistics Netherlands
Avatar
Well, it is the WindowsBase that gives the exception. The timing is wrong anyway, you never know when this destructor will execute, due to the Garbage collector thingie;)

Maybe you can suggest an event that occurs when the syntaxeditor is destroyed?

Regards,
Martin
Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Martin,

The exception you described is usually handled by "dispatching" whatever code you are executing to make sure it happens on the main thread. You can do this by getting the SyntaxEditor's Dispatcher and calling Invoke() on it with the code to execute. That makes sure it executes on the UI thread so this doesn't happen. Even if you don't have a SyntaxEditor instance available, you could do the same with any other UI control.


Actipro Software Support

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.