In an attempt to create a 'System.InvalidOperationException: Cross-thread operation'
I came accros the strange behaviour that i would get an exception only in debug mode.
My test is like this:
- Create a view for some data with data binding to a model
- Create a separate thread (2) changing the model
- Databinding bubbles from the second thread to the UI control and the control throws an exception because it is being changed by a thread that did not create
it.
Now this only was the case in Debug-mode. In release mode everything seemed fine. Seems there is a switch controlling this behaviour
Control.CheckForIllegalCrossThreadCalls that defaults to Debugger.IsAttached. For
a running application this exception is not thrown which might result in unexpected behaviour. By setting
Control.CheckForIllegalCrossThreadCalls = true
the exception does occur.