Can't start multiple processes (C #)

I cannot successfully start multiple processes from the console application. I have a visual studio solution with console app A that needs to run multiple instances of another console app (B).

B runs in a loop, capturing incoming network traffic on the port specified in the process arguments.

To simplify the problem, I removed any network logic and made it as simple as possible, but I still have the same problem.

Code for A, where Test.exe is B's console application:

   static void Main(string[] args)
   {
        try
        {
            for (int i = 0; i < 5; i++)
            {

               System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo { FileName = "Test.exe" });                  

            }

        }
        catch (Exception ex)
        {
            Console.WriteLine("Error: " + ex.Message);
        }

    }

      

Code for B:

    static void Main(string[] args)
    {
        int counter = 0;
        while (Console.KeyAvailable == false || Console.ReadKey().Key != ConsoleKey.Escape)
        {
            Console.WriteLine("" + counter);
            System.Threading.Thread.Sleep(1000);
            counter++;
        }
        Console.ReadLine();
    }

      

As soon as I run Console Application A in Visual Studio Debug, it pops up as intended, but only one window B pops up, starting to count as indicated. However, if I look in my Task Manager, I see that there are actually two Test.exe running, where one uses 116K memory and the other uses 180,000K memory.

Once the counter reaches 15, it closes and reopens two new windows that start counting from 0. This behavior continues by opening new instances of B every time the counter reaches 15 until 5 instances are started as specified in A.

Obviously this is not what I intended, I want A to run B 5 times (in this example) immediately without waiting for the exit to complete.

+3


source to share


1 answer


After reinstalling .net and removing some functionality, I am no longer needed, it finally works as intended. Running 50 instances is not a problem, and the strange memory usage is no longer apparent.



The contender was either the Windows Phone SDK or Windows Azure for VS.

0


source







All Articles