Why does Thread.Sleep() freeze the Form?

前端 未结 6 948
忘掉有多难
忘掉有多难 2021-01-22 03:38

I try to experiment with Thread.Sleep(). I created basic Windows Forms application with one button.

    private void button1_Click(object sender, Ev         


        
6条回答
  •  耶瑟儿~
    2021-01-22 04:04

    If you're new to multithreading, I strongly encourage you to look at the Task Parallel Library (TPL). It simplifies threading, and gives you tools to help guarantee callback (continuation) threads occur on the UI thread.

    The TPL is in the System.Threading.Tasks namespace.

    Update: just seen your comment about .Net v2. TPL was introduced in .NET v3.5 or possibly as late as v4.

提交回复
热议问题