Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asynchronous Execution in windows forms

Tags:

c#

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.

like image 487
RSP Avatar asked Oct 25 '11 11:10

RSP


1 Answers

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.

like image 180
Louis Kottmann Avatar answered Oct 04 '22 12:10

Louis Kottmann