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