[英]C# wait for all threads to finish in Main()
我一直在編寫多線程應用程序以解決迷宮問題。 我從Program Class
Main()
方法開始一個新線程,開始解決迷宮問題。 如果發現分支,他將調用一個靜態方法來創建新線程。 我如何等待在后台運行的所有線程完成,以便例如顯示完成消息?
這是我要做的事情的基本內容:
var explorer = new Explorer(/*Some arguments*/);
var thread = new Thread(explorer.Explore) {Name = "Thread 0"};
thread.Start();
//Thread_0_and_Threads_he_generates_through_static_class.Join()
Console.WriteLine("I'm done bro.");
Console.ReadKey();
有沒有辦法做到這一點? 老實說,第一次使用這種方式使用多線程,因此我為糟糕的代碼表示歉意。 我將很樂意提供任何其他信息。 提前致謝。
也許您正在尋找Thread.Join() ?
您可能還會覺得這篇文章有用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.