相同的exe文件,多进程和不同的输入参数

时间:2014-10-18 02:57:53

标签: c# multiprocessing

我有一个exe文件,比如XYZ.exe,它接收一个csv文件,并做一些其他的操作,比如根据csv文件中的内容查询数据库。

现在,有4个csv个文件,file_1.csv到file_4.csv,格式相同,但内容不同。我想做的是初始化4个进程,所有运行XYZ.exe,每个进程都有一个csv文件。他们都在后台运行。

我试过使用Process.Start(@“XYZ.exe”,输入参数)。但是,看起来第二个进程在第一个进程完成之前不会启动。我想知道如何更改代码以完成工作。

2 个答案:

答案 0 :(得分:1)

使用此过载:
    Process.Start方法(ProcessStartInfo)

@JimMischel你应该获得积分奖励!

答案 1 :(得分:0)

我认为你在这里尝试做的是:多线程,我的想法是你可以创建一个启动4个线程的应用程序,然后将它们一起启动,就像这样:

using System.Threading;


{
    class Program
    {
        static void Main(string[] args)
        {
            //Here is your main program :

            //Initiate the thread (tell it what to do)
            ThreadStart testThreadStart = new ThreadStart(new Program().testThread);

            //Create 4 Threads and give the Path of the 4 CSV files to process
            Thread Thread1 = new Thread(() => testThreadStart(PathOfThe1stCSVFile));
            Thread Thread2 = new Thread(() => testThreadStart(PathOfThe2ndCSVFile));
            Thread Thread3 = new Thread(() => testThreadStart(PathOfThe3rdCSVFile));
            Thread Thread4 = new Thread(() => testThreadStart(PathOfThe4thCSVFile));

            //Start All The Threads Together
            testThread1.Start();
            testThread2.Start();
            testThread3.Start();
            testThread4.Start();

            //All The Threads  are finished
            Console.ReadLine();
        }


        public void testThread(String CSVfilePathToProcess)
        {
            //executing in thread
            //put the : Process.Start(@"XYZ.exe", input arguments). here !!!
            //and put the CSVfilePathToProcess as arguments
        }
    }
}

编辑:如果多线程对你来说有点复杂,你也可以使用backgroundworker in C#,但想法是一样的。

相关问题