Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I keep a responsive UI while processing large amounts of data?

I am creating winform to process (convert txt files to tiff) large amount of files. I put all the code behind a button (btnProcess). Is this a good idea? It works but I noticed when I go away from the winform and come back to this I see blank window until the process is complete. I heard about background worker. what is the purpose of background worker?

like image 930
Jamil Ferdaus Avatar asked Dec 27 '10 14:12

Jamil Ferdaus


1 Answers

What you need here is multi-threading. That means that two (or more) threads of code would run in parallel. One of them would be the UI thread, the one responsible for drawing the window. In your case you are running your code in the UI thread and thus blocking the UI rendering while your code is running.

The purpose of the BackgroundWorker is to start an operation on a new thread and is what you need.

like image 171
Xavier Poinas Avatar answered Sep 21 '22 03:09

Xavier Poinas