求助,c#多线程问题。(初学者)

下面是我写的一段程序,我设置了11个命令,但是他每次只运行了6个,我一直不解!希望有人帮我解答?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace xiancheng7.25
{
class Program
{
static void Main(string[] args)
{
//Thread t1 = new Thread(new ThreadStart(Thread1));
//Thread t2 = new Thread(new ThreadStart(Thread2));
//Thread t3 = new Thread(new ThreadStart(Thread3));
//Thread t4 = new Thread(new ThreadStart(Thread4));
//Thread t5 = new Thread(new ThreadStart(Thread5));
Thread t6 = new Thread(new ThreadStart(Thread6));
Thread t7 = new Thread(new ThreadStart(Thread7));
Thread t8 = new Thread(new ThreadStart(Thread8));
Thread t9 = new Thread(new ThreadStart(Thread9));
Thread t10 = new Thread(new ThreadStart(Thread10));
Thread t11 = new Thread(new ThreadStart(Thread11));
//t1.Priority = ThreadPriority.Normal;
//t2.Priority = ThreadPriority.Normal;
//t3.Priority = ThreadPriority.Normal;
//t4.Priority = ThreadPriority.Normal;
//t5.Priority = ThreadPriority.Normal;
t6.Priority = ThreadPriority.Normal;
t7.Priority = ThreadPriority.Normal;
t8.Priority = ThreadPriority.Normal;
t9.Priority = ThreadPriority.Normal;
t10.Priority = ThreadPriority.Normal;
t11.Priority = ThreadPriority.Normal;
//t1.Start();
//t2.Start();
//t3.Start();
//t4.Start();
//t5.Start();
t6.Start();
t7.Start();
t8.Start();
t9.Start();
t10.Start();
t11.Start();
}
public static void Thread1()
{
//string str = Console.ReadLine();
dosth();
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false; //是否使用操作系统shell启动
p.StartInfo.RedirectStandardInput = true;//接受来自调用程序的输入信息
p.StartInfo.RedirectStandardOutput = true;//由调用程序获取输出信息
p.StartInfo.RedirectStandardError = true;//重定向标准错误输出
p.StartInfo.CreateNoWindow = false;//不显示程序窗口
p.Start();//启动程序

        //向cmd窗口发送输入信息
        p.StandardInput.WriteLine("d:");
        p.StandardInput.WriteLine("cd d:\\test\\a");
        // p.StandardInput.WriteLine("make clean");
        p.StandardInput.WriteLine("make ");
        //向cmd窗口发送输入信息
        p.StandardInput.WriteLine("exit");
        //获取cmd窗口的输出信息
        string output = p.StandardOutput.ReadToEnd();


        p.WaitForExit();//等待程序执行完退出进程
        p.Close();


        Console.WriteLine(output);
       // Console.ReadLine();

    }
    public static void Thread2()
    {
        System.Diagnostics.Process p = new System.Diagnostics.Process();
        p.StartInfo.FileName = "cmd.exe";
        p.StartInfo.UseShellExecute = false;    //是否使用操作系统shell启动
        p.StartInfo.RedirectStandardInput = true;//接受来自调用程序的输入信息
        p.StartInfo.RedirectStandardOutput = true;//由调用程序获取输出信息
        p.StartInfo.RedirectStandardError = true;//重定向标准错误输出
        p.StartInfo.CreateNoWindow = false;//不显示程序窗口
        p.Start();//启动程序

        //向cmd窗口发送输入信息
        p.StandardInput.WriteLine("d:");
        p.StandardInput.WriteLine("cd d:\\test\\b");
        // p.StandardInput.WriteLine("make clean");
        p.StandardInput.WriteLine("make ");
        //向cmd窗口发送输入信息
        p.StandardInput.WriteLine("exit");
        //获取cmd窗口的输出信息
        string output = p.StandardOutput.ReadToEnd();


        p.WaitForExit();//等待程序执行完退出进程
        p.Close();


        Console.WriteLine(output);
        //Console.ReadLine();


    }

    …………………………………………
    public static void dosth()
    {//用来模拟复杂运算

        for (int j = 0; j < 10000000; j++)
        {
            int a = 15;
            a = a * a * a * a;
        }
    }
}

}

1个回答

t11.Start();
后面加上
Console.Read();
让主线程保持住。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问