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

前端 未结 3 1028
野性不改
野性不改 2020-12-06 13:24

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 noti

3条回答
  •  悲哀的现实
    2020-12-06 14:12

    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.

提交回复
热议问题