我似乎無法創建前臺任務。 我的主線程是調用另一個線程,然後退出。 其他線程想永遠運行如何創建前臺任務?
void MainThreadMain()
{
task_main = Task.Factory.StartNew(() => OtherThread()) ;
return;
}
void OtherThread()
{
while(true)
{
TellChuckNorrisJoke();
}
}
我怎麼能保證task_main將繼續運行,甚至主線程死了嗎? 我認爲金正日做:
task_main.IsBackgorund = false;
,但沒有這樣的選擇:\ 我可以讓我的主線程等待從我的其他線程的信號,它傳遞給前臺模式。但那簡直是愚蠢的。
您可以通過*不*使用線索來確保這一點。只需在重命名後直接調用OtherThread()即可。 – 2012-03-14 11:54:34
這篇文章可能會有所幫助。 http://stackoverflow.com/questions/6156878/can-threads-started-by-tasks-parallel-library-act-as-foreground-threads – Krishna 2012-03-14 11:56:07