C# Threading using invoke, freezing the form

前端 未结 6 1493
被撕碎了的回忆
被撕碎了的回忆 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:25

    You're still performing a single-threaded task, just re-launching it on the UI thread if needed.

    for (int i = 0; i < 500; i++){
        string text = ""+i;
        textBox.BeginInvoke((MethodInvoker)delegate()
                {
                    textBox.Text += text;
                });
    }
    

提交回复
热议问题