Update Label while processing in Windows Forms

前端 未结 5 1875
情歌与酒
情歌与酒 2020-12-13 13:05

What is the best way to update a label on a Windows Forms application while processing?

I have a loop that does some processing to files on the user\'s system when t

5条回答
  •  不思量自难忘°
    2020-12-13 13:43

    You should be doing this on another thread, and then updating your UI thread from that thread. You are blocking further processing by performing this work on the UI thread.

    If you can't move this code to the UI thread, then you could always call Application.DoEvents, but I strongly suggest you explore these options first:

    • System.ComponentModel.BackgroundWorker
    • System.Threading.ThreadPool
    • System.Threading.Thread
    • System.Threading.Tasks namespace

提交回复
热议问题