Invalid Cross Thread Operations -- How To run class code in a thread and write to the form
If you've ever worked with windows forms, one of the most annoying things that you can ever do is write some massive process and then push go, only to 'freeze' your form in place or lock it on the screen. If nothing else, it will turn completely white and you can't see anything! The solution to this problem, of course, is to run your code in a thread. This allows you to continue working with the form as the code runs asynchronously in the background. But what happens when you need your thread to alter information on the form, such as change the value of a control on the form for display to the user? You get a nice friendly error message that says: Cross-thread operation not valid: Control 'blahblahblah' accessed from a thread other than the thread it was created on. To illustrate, I've built a little project I've dubbed as ThreadSmart. It's a simple windows application which contains a main form and a class. The form is just called frmMain and...