01./// <summary>
02. /// 多线程方法重入问题按钮
03. /// </summary>
04. /// <param name="sender"></param>
05. /// <param name="e"></param>
06. private void btnMethodProblem_Click(object sender, EventArgs e)
07. {
08. Thread thread = new Thread(ChangeText); //这里可以直接把方法传入
09. thread.IsBackground = true; //把线程设置为后台线程
10. thread.Start();
11. }
12.
13. /// <summary>
14. /// 修改文本框里面的内容(循环取得文本框的值,然后让它自增,最后再把它赋值给文本框)
15. /// </summary>
16. private void ChangeText()
17. {
18. for (int i = 0; i < 10000; i++)
19. {
20. int a = int.Parse(txtNum.Text);
21. a++;
22. txtNum.Text = a.ToString();
23. }
24. }
运行这段程序,其结果如图所示: |