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?
Sheldon LivingstonConsultantAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shaun VermaakTechnical SpecialistCommented:
You need to change it in the Assembly Information dialogue box
Assembly.png
0
AndyAinscowFreelance programmer / ConsultantCommented:
>>I've written a Visual Studio 2017 C# that I want to run 2 instances of.

That should not be a problem - one usually has to code something to prevent a second instance running.
2

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Shaun VermaakTechnical SpecialistCommented:
Correct, misread question
0
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

AndyAinscowFreelance programmer / ConsultantCommented:
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.
0
it_saigeDeveloperCommented:
*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.Capture.PNGBy 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.Capture.PNG
-saige-
0
Sheldon LivingstonConsultantAuthor Commented:
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.
0
it_saigeDeveloperCommented:
Noone here misunderstood your requirements.  As we have stated, by default, C# does not restrict multiple running instances...  Proof of concept, a simple hello world application:
using System;
using System.IO;
using System.Reflection;

namespace EE_Q29088346
{
    class Program
    {
        static void Main(string[] args)
        {
            Assembly asm = Assembly.GetExecutingAssembly();
            Console.WriteLine($"Hello world from {new FileInfo(asm.Location).Name}");
            Console.ReadLine();
        }
    }
}

Open in new window

In the bin folder, I have made a copy of my application, so we have EE_Q29088346.exe and EE_Q29088346 - Copy.exe -Capture.PNGStarting both applications results in the following output -Capture.PNGTaking a look at task manger -Capture.PNGIt might be beneficial at this point for you to provide us the code that is not working.

-saige-
1
AndyAinscowFreelance programmer / ConsultantCommented:
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.
0
Sheldon LivingstonConsultantAuthor Commented:
AndyAinscow... any thoughts on why my program isn't working (as initially explained)?  Once instance starts up only when the first instance is closed.
0
AndyAinscowFreelance programmer / ConsultantCommented:
Yes I have thoughts and I have told you what they are.  You have coded it to explicitly stop the second instance starting.
0
AndyAinscowFreelance programmer / ConsultantCommented:
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.
0
Sheldon LivingstonConsultantAuthor Commented:
I have not explicitly coded to prevent multiple instances... and I don't see the same "single instance" setting in VS 2017.
0
AndyAinscowFreelance programmer / ConsultantCommented:
>>I have not explicitly coded to prevent multiple instances

Maybe not intentionally, but somewhere you have.  (The single instance is a VB.NET setting - hence my earlier comments about that difference to C# where there is no setting to prevent two instances running, one must specifically write code that stops a second instance)

Try a quick experiment.
Create a new winforms project in C#.
compile it.
Double click the exe created to start an instance then double click again.  A second instance will start.
0
Sheldon LivingstonConsultantAuthor Commented:
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.
0
it_saigeDeveloperCommented:
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) -Capture.PNGAnd Task Manager shows -Capture.PNGI 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-
0
AndyAinscowFreelance programmer / ConsultantCommented:
>>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.
0
AndyAinscowFreelance programmer / ConsultantCommented:
Somewhere there is code to prevent the second instance starting.
0
Sheldon LivingstonConsultantAuthor Commented:
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?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.