I'm writting a Windows Forms application in C# that executes a lot of long-running procedures on a single button click. This make the GUI to freeze till the execution. Also, during the execution, i'm logging the information & status to a List Box. However, untill the execution is complete, the status is not getting updated in the list box. How should i code so that the status is getting updated in list box in parallel with the execution and so that the GUI doesn't freeze.
I'm new to threading. Can you please give some example of how this is done?
Thanks in advance for your help.
The simplest yet efficient way to handle these scenarios, is to use a BackgroundWorker
.
You put your heavy code in the DoWork event handler, and update your GUI through the ProgressChanged event handler.
You can find a tutorial here
Or even better they made a "how to" at msdn
If you have more specific questions after reading it, i'll be happy to oblige.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With