Reputation: 1059
I know in VS 2013 it is possible to run multiple projects at once, but I need to start a single project with multiple instances (would like to be able to set the number).
The purpose for this requirement is I need to test code that interacts with a server component and want to test its safety if multiple clients are picking at it at, if they make concurrent requests, etc.
To clarify, I want to start X number of project instances at once.
Upvotes: 0
Views: 260
Reputation: 9041
You can use Process.Start()
from the System.Diagnostics
namespace, and within Main(string[] args)
check if args has any data. One of those elements, depending how the arguments are passed in, would be the number of times the program needs to launch itself. Use that argument in a loop and launch the program again without startup arguments
public static void Main(string[] args)
{
if (args.Length > 0)
{
// First element is the number of times to launch itself
int numberOfClients = Convert.ToInt32(args[0]);
// Launch the same application multiple times
for (int i = 0; i < numberOfClients; i++)
{
Process.Start(System.Reflection.Assembly.GetEntryAssembly().Location);
}
}
Console.WriteLine("I've been launched");
Console.ReadLine();
}
MyApp.exe 5
Upvotes: 1
Reputation: 8792
You just start the instance without debugging: DEBUG -> Start Without Debugging (or Ctrl+F5). You can start another instance without debugging while one is already running. This way you can have several instances at the same time.
EDIT:
You can always invoke the exe from a command line and have a script looping through it several times. The command below did the trick for me:
for %i in (1 2 3 4 5) DO myApp.exe
If you are running a command line program to have it in separate command line windows you start it with start cmd /k
for %i in (1 2 3 4 5) DO start cmd /k myApp.exe
Only probably use an absolute path to run your program because the new command line dialog is oppened in a default directory. And apply /k
switch which will execute the program after the command line is opened.
Upvotes: 2