• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 87
  • Last Modified:

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?
0
Sheldon Livingston
Asked:
Sheldon Livingston
  • 8
  • 5
  • 3
  • +1
3 Solutions
 
Shaun VermaakTechnical Specialist/DeveloperCommented:
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
 
Shaun VermaakTechnical Specialist/DeveloperCommented:
Correct, misread question
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 8
  • 5
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now