Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I Yield to the UI thread to update the UI while doing batch processing in a WinForm app?

Tags:

c#

.net

winforms

I have a WinForms app written in C# with .NET 3.5. It runs a lengthy batch process. I want the app to update status of what the batch process is doing. What is the best way to update the UI?

like image 222
Guy Avatar asked Sep 19 '08 22:09

Guy


1 Answers

Use Backgroundworker, and if you are also trying to update the GUI thread by handling the ProgressChanged event(like, for a ProgressBar), be sure to also set WorkerReportsProgress=true, or the thread that is reporting progress will die the first time it tries to call ReportProgress...

an exception is thrown, but you might not see it unless you have 'when thrown' enabled, and the output will just show that the thread exited.

like image 86
frediano Avatar answered Sep 26 '22 02:09

frediano