Link to home
Start Free TrialLog in
Avatar of Sheldon Livingston
Sheldon LivingstonFlag for United States of America

asked on

I want more than one instance of my C# program to run.

I've written a Visual Studio 2017 C# that I want to run 2 instances of.  I started this as TestProject.  

I tried renaming TestProject.exe to Test1Project.exe... task manager still shows it as TestProject which prevents Test2Project from running (as it is really TestProject as well).

I tried renaming the assembly name... same issue... TestProject is really running.

Thoughts?
Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

You need to change it in the Assembly Information dialogue box
User generated image
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Correct, misread question
ps.  You explicitly say C# program.  If it is a VB.NET program then say so - there is a simple way to make only one instance run, maybe you have that activated.
*NO POINTS*

Exactly as Andy states, C# programs, by default, do not prevent multiple running instances.  You have to manually implement the single instance logic.User generated imageBy way of comparison, while VB.NET, by default does not prevent multiple running instances either; VB.NET does, however, provide an option which automatically implements the single instance logic.User generated image
-saige-
Avatar of Sheldon Livingston

ASKER

To make this clear, I WANT 2 instances of the program to run.  When I double click Test1Project I see TestProject running in Task Manager.  When I then double click Test2Project nothing happens.  I wait and I wait.  I then kill TestProject in Task Manager and the second iteration of the program will open... again Task Manager will show TestProject is running.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
As I said initially.  With a C# program two instances WILL start and run by doing what you stated.  For a C# program you have specifically added code to prevent a second instance running.  remove that code and it will do what you want.
AndyAinscow... any thoughts on why my program isn't working (as initially explained)?  Once instance starts up only when the first instance is closed.
Yes I have thoughts and I have told you what they are.  You have coded it to explicitly stop the second instance starting.
Paste the code in the program.cs file - that is the most likely (but not the only) place where you would have such code to prevent a second instance starting.
I have not explicitly coded to prevent multiple instances... and I don't see the same "single instance" setting in VS 2017.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This program, as you mentioned earlier, is a .NET program.  It is also a winforms program.  In the past when I have created single instance programs the second program doesn't sit idely by waiting for the first instance to close.
Just to add to this conversation, there is also no need to rename the application to support multiple instances either.  Refer to my previous example for the code:

Here I have started up 4 instances (two of each one) -User generated imageAnd Task Manager shows -User generated imageI agree with Andy that something in your code is explicitly preventing this.  We can speculate all we want, but unless you show us some code, we cannot really help.

-saige-
>>In the past when I have created single instance programs the second program doesn't sit idely by waiting for the first instance to close.

I agree, that is an unusual behaviour.  Also an indication you have made a mess somewhere in your code to create that effect.  To start with (a repeat) please post the code in your program.cs file.
Somewhere there is code to prevent the second instance starting.
Perhaps the reason that multiple instances won't run is because the program uses 2 DLLs?  Is there an issue with the DLLs preventing a secondary program from opening?  A "sharing" issue?