簡體   English   中英

這兩種做法之間有什么區別:

[英]Whats the difference between these two practices:

我是多線程技術的新手,正在關注Albahari Joe撰寫的書並觀看有關Pluralsight的課程,但是當我想更多地了解線程以及如何正確,安全和有效地使用線程時,我經常會陷入困境。 我在這里搜索了一種解決方案,但找不到。 因此,請不要激怒我的基本問題! 任何幫助,將不勝感激。 提前致謝。

new Thread(Work).Start();     
OR
Thread t = new Thread(WriteB); t.Start();

唯一的區別是,在第二行中,您仍然可以通過變量t訪問新的Thread實例。

例如,如果您想等待線程完成,則可以使用:

Thread t = new Thread(WriteB); 
t.Start();
// ... do work while the other thread also does work ...
t.Join();

如果不將Thread分配給變量,您將無法做到這一點。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM