I want to disable cross-threading exceptions in my WPF application. In a Windows Forms application, I would do this:
Control.CheckForIllegalCrossThreadCalls = False
How can I do the same in a WPF application?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In WPF the responsibility of checking for illegal cross thread calls rests with the Dispatcher object via the CheckAccess() member. Objects like DependencyObject use their associated Dispatcher to check for an illegal thread access on almost all API calls.
Unlike WinForms, there is no way to disable this check in WPF. It is on by default and cannot be disabled.
As to why this is the case (bit of speculation here). The CheckForIllegalCrossThreadCalls member was added in .net 2.0. The reason was that accessing a control from a different thread was already illegal, there was just no enforcement of this. This resulted in lots of unpredictable user scenarios as instead of proactively crashing, the control would have unpredictable behvaior.
In 2.0, the WinForms team added the CheckForIllegalCrossThreadCalls as a way of proactively preventing these scenarios from happennig. But because some people were getting away with it they had to insert a way to turn it off in order fro applications to be backwards compatible.
If you need to turn this off, there is a bug in your code. You would be much better served by finding and fixing the bug as opposed to disabled the check.