The Application.DoEvents trick given by somebody else works well, but if there are a lot of iterations and/or a lot of events somewhere else, it sometimes slows down things too much.
An alternative is to use a BackgroundWorker control in the form. This control is an easy way to start a new thread from a Windows Form and has a few properties and methods that can prove to be useful in some circumstances.
You put the code to be executed in its DoWork event.
To start the job, you call its RunWorkerAsync method.
If you need to cancel before it has finished, you call its CancelAsync method.