C# Threading using invoke, freezing the form

前端 未结 6 1479
被撕碎了的回忆
被撕碎了的回忆 2020-12-31 23:02

I\'m trying to use threads and prevent the program from freezing while the thread is busy. It should show the progress (writing of 0\'s / 1\'s) and not just show the result

6条回答
  •  攒了一身酷
    2020-12-31 23:33

    This solution works ! Have checked it.

    The problem is you keep telling the UI thread to change the Text, but never letting it have time to show you the updated text. To make your UI show the changed text, add the Application.DoEvents line like this :

    textBox.Text += text;
    Application.DoEvents();
    

    p.s. : Remove the else block of your If / Else loop, it is redundant, and also as pointed by others there is not any use of creating those 2 Threads as all they are doing is post the message on the UI Thread itself.

提交回复
热议问题