Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it safe just to set CheckForIllegalCrossThreadCalls to false to avoid cross threading errors during debugging?

In WinForms applications, is it safe just to set CheckForIllegalCrossThreadCalls to FALSE to avoid cross threading errors during debugging?

CheckForIllegalCrossThreadCalls = false;
like image 923
Roman Ratskey Avatar asked Nov 12 '12 14:11

Roman Ratskey


1 Answers

No, that's not safe. The Winforms code that checks for threading mistakes is very important, the trouble that causes is extremely hard to diagnose. The biggest problem is that it doesn't cause consistent failure, your app will misbehave randomly and deadlock or crash only once a month. Or never at all, until you make a minor change. Or only on a particular user's machine, you'll blame the user instead of your code.

The only reason the CheckForIllegalCrossThreadCalls property exists in the first place is to keep .NET 2.0 and up compatible with buggy .NET 1.x programs where this threading safety test was not performed. Backward compatibility for bugs ;-P

like image 165
Hans Passant Avatar answered Oct 25 '22 23:10

Hans Passant