Wednesday, February 15, 2006

C# Invalid Cross Thread Operation

In .NET Framework 2.0 with default settings you can not change a Windows Control Property from an external thread, and if you try to do that you will get the following Exception
"Invalid Cross-Thread Operation"

to avoid this exception you can disable the checking for invalid Cross-Thread Operation by setting this static Property to false:
Control.CheckForIllegalCrossThreadCalls = false;

This settings is not recommended it is done only to avoid the exception appearing while debugging, it may cause serious problems if you disabled it (its done mainly to warn you while you debug your application).

To See other techniques to avoid this problem, see:

Tuesday, February 07, 2006

Invalid character value for cast specification

If you catch this error and you are trying to use a DateTime Value with SQL Server then check that your date in this range:

1/1/1753 to 31/12/9999

it will probably fix the problem