How can I wait for a thread to finish with .NET?

前端 未结 10 2153
有刺的猬
有刺的猬 2020-11-22 10:27

I\'ve never really used threading before in C# where I need to have two threads, as well as the main UI thread. Basically, I have the following.

public void S         


        
10条回答
  •  清酒与你
    2020-11-22 10:55

    When I want the UI to be able to update its display while waiting for a task to complete, I use a while-loop that tests IsAlive on the thread:

        Thread t = new Thread(() => someMethod(parameters));
        t.Start();
        while (t.IsAlive)
        {
            Thread.Sleep(500);
            Application.DoEvents();
        }
    
    

提交回复
热议问题