2014-10-18 25 views
1

我有一个exe文件,说XYZ.exe它需要一个csv文件,并做一些其他操作,如根据csv文件中的事情查询数据库。相同的exe文件,多进程和不同的输入参数

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

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

+2

[Process.Start(string,string)](http://msdn.microsoft.com/zh-cn/library/h6ak8zt5(v = vs.110).aspx)的备注部分说:“如果进程已经运行,则不会启动其他进程。“您可能希望使用[this overload](http://msdn.microsoft.com/en-us/library/0w4h05yb(v = vs.110).aspx)。 – 2014-10-18 03:12:10

+1

[这个答案也许对你有用。](http://stackoverflow.com/questions/10788982/is-there-any-async-equivalent-of-process-start) – WhoIsRich 2014-10-18 03:15:01

+0

我编辑过你的标题。请参阅:“[应该在其标题中包含”标签“](http://meta.stackexchange.com/questions/19190/)”,其中的共识是“不,他们不应该”。 – 2014-10-20 20:16:34

回答

1

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

@JimMischel你应该得到奖励分!

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#,但这个想法是一样的。

+1

你怎么知道这是一个I/O绑定操作?你可以读一个1Mega咬文件并处理它半个小时!? – 2014-10-18 05:34:42

相关问题