Update: here is an MSDN article How to: Make Thread-Safe Calls to Windows Forms Controls. It states:
The .NET Framework helps you detect when you are accessing your controls in a manner that is not thread safe. When you are running your application in the debugger, and a thread other than the one which created a control tries to call that control, the debugger raises an InvalidOperationException with the message, "Control control name accessed from a thread other than the thread it was created on."
This exception occurs reliably during debugging and, under some circumstances, at run time.
My previous experience was that the exception was thrown at run time, too.
Thanks to Spence for pointing me in the right direction.
I have a pretty common error in WinForms app: background thread accessing UI controls directly instead of using Control.BeginInvoke().
My problem is the following: I see the InvalidOperationException "Cross-thread operation not valid: Control 'uxCheckStatus' accessed from a thread other than the thread it was created on." in debugger on background thread, but then it is swallowed somewhere in WinForms internals.
I expect it to kill the background thread and entire application.
Moreover, the code that is triggering it uxCheckStatus.Text = "success";
sometimes gets executed during/after exception is thrown i.e. label text reads 'success'! I'm basically lost. Anyone else experiencing this behavior?
I reproduce it on completely new WinForms solution with 1 button, both using ThreadPool and Thread for evil background thread.
If I throw a new InvalidOperationException() on background thread, it does kill the application. So my only guess is that WinForms handles this specific exception somewhere, but I cannot find references to this behavior on the web.
I run .NET 3.5, VS 2008.