You need to make sure the loop processing the file runs on a different thread to the UI. There are several ways to achieve this see the links at the bottom of my post for examples. In general, only UI operations (those directly related to the UI, button hanlders, control initialisation etc) should block the UI Thread. Additionally,
only the UI thread can update the UI (otherwise an exception is thrown). So:
1. Start the Processing loop on its own thread.
2. Disable the "Start" button or whatever starts the process (UI thread, as part of button on-click for example).
3. If you have added a cancel button, it will remain enabled & clickable.
Now one of the things can happen, either:
a) The user presses the cancel button, in which case the loop should cease, and the start button should be re-enabled.
b) The loop completes processing. The
UI thread must do the update to report back to the user and re-enable the Start button. In winforms this is Done via the
Invoke
method on the control ( See
http://www.yoda.arachsys.com/csharp/threads/winforms.shtml[
^] for an example. On WPF you need to call
Dispatcher.Invoke
. See
http://msdn.microsoft.com/en-us/magazine/cc163328.aspx[
^] figure 4 for guidance