1

I have an exe file, say XYZ.exe which takes in a csv file, and do some other manipulation, like querying DB based on the things in csv file.

Now, there are 4 csv files, file_1.csv to file_4.csv, same format, but different contents. What i wanna do is to initial 4 process, all running XYZ.exe, and each with one of the csv files. They all run in background.

I have tried to use Process.Start(@"XYZ.exe", input arguments). However, it looks like the second process would not start till the first process finishes. I wonder how should i change the code to accomplish the work.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Decipher
  • 194
  • 2
  • 11
  • 2
    The Remarks for [Process.Start(string, string)](http://msdn.microsoft.com/en-us/library/h6ak8zt5(v=vs.110).aspx) say, in part: "If the process is already running, no additional process is started." You probably want to use [this overload](http://msdn.microsoft.com/en-us/library/0w4h05yb(v=vs.110).aspx) instead. – Jim Mischel Oct 18 '14 at 03:12
  • 1
    [This answer may also be useful to you.](http://stackoverflow.com/questions/10788982/is-there-any-async-equivalent-of-process-start) – WhoIsRich Oct 18 '14 at 03:15
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Oct 20 '14 at 20:16

2 Answers2

1

Use this overload:
Process.Start Method (ProcessStartInfo)

@JimMischel you should be rewarded for points!

Decipher
  • 194
  • 2
  • 11
0

i think what you are trying to do here is called : Multithreading, my idea is that you can create an application that initiate 4 threads and you start all of them together, it is something like that :

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
        }
    }
}

Edit : If Multithreading is little complicated for you, you can also use backgroundworker in C# , but the idea is the same.

KADEM Mohammed
  • 1,650
  • 2
  • 23
  • 45