J
Jonathan Wood
I want to run a lengthy operation, yet still have the UI be responsive to
user input. Therefore, I decided to create my first multi-threaded C#
application and run the lengthy process in the background, and stop if the
main process sets a flag.
The basic approach I took is the one described at
http://support.microsoft.com/kb/815804. My code's a bit different but very
similar. Instead of manipulating a progress bar, my background thread
instead updates a label contrl named label1.
Everything works until I attempt to update the label control. I then get the
error "Cross-thread operation not valid: Control 'label1' accessed from a
thread other than the thread it was created on."
A background thread doesn't seem very useful if I can't modify the form. And
why does the Microsoft example work if this is not allowed?
Thanks for any tips!
Jonathan
user input. Therefore, I decided to create my first multi-threaded C#
application and run the lengthy process in the background, and stop if the
main process sets a flag.
The basic approach I took is the one described at
http://support.microsoft.com/kb/815804. My code's a bit different but very
similar. Instead of manipulating a progress bar, my background thread
instead updates a label contrl named label1.
Everything works until I attempt to update the label control. I then get the
error "Cross-thread operation not valid: Control 'label1' accessed from a
thread other than the thread it was created on."
A background thread doesn't seem very useful if I can't modify the form. And
why does the Microsoft example work if this is not allowed?
Thanks for any tips!
Jonathan