views:

730

answers:

2

Guys, WPF project is not accepting this property definition when starting a thread. Anybody knows the equivalent of the following in WPF?

Control.CheckForIllegalCrossThreadCalls = False

Thanks in advance!

+3  A: 

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.

JaredPar
Actually, I do understand that this is not the perfect way of doing things. The problem is, I haven't found in MSDN any example on how to work with the Dispatcher that come in VB.net. All examples I found so far are only C# and I don't really know this language. Thanks for your response.
TuxMeister
+1  A: 

I have the same issue and I think this is the solution

amr osama
+1 this is the correct answer!
egrunin