Start multiple instances of console app in Visual Studio (with different args)? - c#

This question ...and the answer shows how to start another instance of a console app in Visual Studio when you already have one running.
I want to do the same BUT passing different args[]. For example, when debugging I want to start up 2 instances of MyConsoleApp.exe as follows...
"MyConsoleApp.exe Agent1"
"MyConsoleApp.exe Agent2"
Does anyone know how to do this?
(Using Visual Studio 2015 Pro)

As far as I know you can't. What I'd do is open the solution in two VS instances and run it. Or else you can give it a go the following way too ( haven't tried this but ideally it should work)
Create two console projects and add all your files as 'linked' files on both projects ( the same .cs files being used on both projects)
Go to the solution and set one project as 'Start with Debugging' and other as start without debugging. ( or may be both as Start with Debugging- depending on your scenario) here is how you could do this.

Related

How to run separate files in Visual Studio 2019 C#

I am trying to run another file in Visual Studio 2019. I have the Program.cs and then Variables.cs which is dedicated to variables. I am following a tutorial.[Here i have 2 files Program.cs and Variables.cs. How can i run Variables.cs. If i try and run it i get an error called "There is already a main entry point". Also for the near future lets say i created a file dedicated o arrays or user input. How can i run user input or arrays? Also how can i also have 2 or more C# files in VSCode without getting a problem when running. I am also a beginner in C#
When you right click a different project in your solution, regardless of whether another main() function is already running, you can see a debug option. Mousing over this will allow you to hit Start New Instance, which will run that project simultaneously.

How can I run multiple programs sequentially, from one solution?

I have a Visual studio solution containing multiple programs, each of which contains it's own Class and Main Method. I need to set these programs up to run one after the other, as some of them access the same database tables, and I do not want there to be conflicts.
I have tried setting up dependencies and creating a new program with class dependencies, however, this does not seem to have worked, does anyone have an idea?
Right click on your solution > Properties > Common Properties > Startup project
Select "Multiple startup Projects" and change the value of the Action column from "None" to "Start" or "Start without debugging"
Visual Studio is a development tool. It is not a tool to orchestrate how your application should execute. Your application should also function when executed outside Visual Studio.
With that in mind you need to decide how to partition your application. Right now you seem to have several applications (console programs?) that need to execute one after the other. An easy solution is to create a batch file that executes each in turn. You can also create a separate application that execute each "child" application in sequence using the Process.Start method but why bother when you can create a batch file?
You might also consider merging your different applications into a single application that has a Main method that executes each task in sequence.
Without more information about your problem it is hard to give you specific advice.
You mentioned you have tried "Multiple Startup Projects" approach but did you set the order in which multiple projects run when you start the debugger?
To set the order in which multiple projects run when you start the debugger
Open the Solution Property Pages dialog box.
Select the Startup Project set under Common Properties.
In the pane on the right, select Multiple Startup Project.
Select a project, and then click Move Up to run that project earlier when you start the debugger, or click Move Down to run the project later.
Reference: How to: Modify Project Properties and Configuration Settings
You need run each program in separate Visual Studio instances.

Working with 2 Visual Studio 2015 instances : error CS2012 "file is being used by another process"

With Visual Studio 2013, I used to open 2 instances of Visual Studio :
one for a "server" solution (say a WCF host),
one for a "client" solution (say a WPF app).
The 2 solutions have a common project, but this was not an issue : I could start the first in debug mode, start the second in debug mode, find a bug, stop one to fix the bug, and start it again (without stopping the second).
This scenario is no more possible with VS2015 : when I stop-fix-start one, I get a build error on the common project :
error CS2012: Cannot open 'D:\MyProject\obj\Debug\myCommonLib.dll' for writing --
'The process cannot access the file 'D:\MyProject\obj\Debug\myCommonLib.dll' because it is being used by another process.'
Is there a way to configure this error as "non blocking" for visual studio 2015 OR to go back to the vs2013 behavior ?
EDIT
Process explorer shows this handles when the client app is started :
On VS2013 :
On VS2015 :
==> we can show here 2 more handles on dll in the "obj" folder. This seems to be the problem.
From VS configure a new buid type for the project, this need to be configured the same as the Debug mode. Then run one of them in "Debug" and the other one in "Debug 2".
I hope these picture-guide could help you.
To have a common project in two solutions is simply wrong. If it has worked in VS2013 I would consider it as a bug, which according to you has been fixed in VS2015.
The correct way forward, is to either join the two solutions into one with different projects, or to isolate the common project into a separate solution to help VS2015 distinguish between the three parts:
the server part
the client part
the common part

Debugging an application called from another in Visual Studio?

I have a lobby application which invokes a client-application (think: League of Legends). They're two separate applications and the first invokes the second from itself - how can I get Visual Studio to debug this application as well?
You simply need to launch a separate Visual Studio, and then use Debug | Attach to Process to attach to the other process. The trick is using two Visual Studios.
Debug -> Attach to process
Select the executable from the list.
Make sure to select the right code type with the Select.. button.
Have you tried Debug -> Attach to Process?
Ref: http://msdn.microsoft.com/en-gb/library/vstudio/3s68z0b3.aspx
Like Matthew said Debug|Attach to process. If the other application is in a different service you might also want to look into remote debugging
The other answers are correct, but I just wanted to add another approach:
If you add both projects to a single Visual Studio Solution, you could:
Right-click the solution -> Properties -> Common Properties -> Startup Project
There you would select Multiple startup projects and select both the Lobby and the Client applications.
That way you can debug several VS projects without having to run several VS instances.

How to access break points in two application in the same solution

I have two web applications in the same solution. I put break points in both of them and when debug I can't access but the start up one. How to debug both of them?
Just right click on your project solution in visual studio then go to properties and in Common Properties > Startup Project select Multiple startup projects. Then choose the appropriate action.
That way you will be able to debug both
You can have only one active project at time of compilation/running. By the way, if one active project somehow calls something from another, just press F11 and you will jump into another project and symbols for it will be loaded automatically and you can debug it.
EDIT
If you are asking about debugging 2 projects contemporary in parallel, it's not possible with in one VS. If these are the separate projects that communicate with eash others, let's say chat application, you can naturally, by running two instances of VS and debug communication between them.
Hope this helps.
You should try to open two versions of visual studio, run both solutions, but set the start up project differently for each, and run them both. The two instances of visual studio should catch the break points of their respective start up programs. I know this works for windows/console applications. Although I've never tried it with 2 web applications. You may have to configure the applications to use different ports.

Categories