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?我觉得我会问,因为我有一个习惯,当我尝试做一些我不完全理解的事情时,我会搞砸我的代码。

4

1 回答 1

3

是的,线程可以创建其他线程。请记住,您的程序加载的“默认单线程”只是另一个普通线程,因此当您启动 thread1 时,您已经从一个线程创建了一个新线程

于 2013-06-05T23:03:10.690 回答