1
說我有這樣的代碼:線程是否可以調用線程?
public int A = 0;
//This is the method that will
//be run as a thread
public void Thread1()
{
public bool continue = true;
while (continue == true)
{
if (A==2)
{
Thread t2 = new Thread(new ThreadStart(Thread2));
}
//Some other code here
}
}
//This is the method that Thread1
//will try to run if A = 2
public void Thread2()
{
//Coding in this thread
}
再說說INT A收到來自其他方法或類似的東西設置爲2。 thread1能夠從內部創建新的thread2嗎?我覺得我會問,因爲我有一種習慣,當我嘗試做一些我不完全理解的事情時,會搞亂我的代碼。
從技術上講,線程可以創建另一個線程線程......這一直髮生......你的應用程序以一個主線程開始...... – Yahia
如果你已經測試過了,你會得到答案 – Mzf
「繼續」可能不是C#中最好的變量名稱,因爲它也是一個關鍵詞。 – Inisheer