Posts

Showing posts from March, 2009

Invalid Cross Thread Operations -- How To run class code in a thread and write to the form

Image
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...

The purpose of this blog

This first post is not going to contain anything other than a brief blah blah from me. This blog is going to be my landing place for posting things that I learn or things I want to share, or just plain cool things if I ever happen to find any while I'm programming. I might also post some random thoughts here about coding, or else I could post some general things so I can use this as my own reference going forward. Maybe someone else will find it useful too, who knows. Hopefully it will shape up over the next few years into a pretty cool repository. One final note is that the topics are not going to be presented in any particular order, just as I feel like writing about them. Someday maybe I'll organize it, but don't hold your breath.