473,378 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

How to stop running multiple instances of my App in C#?

How to stop running multiple instances of my App in C#?

Thanx
Nov 13 '05 #1
4 10114
PalB <pa*******@hotmail.com> wrote:
How to stop running multiple instances of my App in C#?


The easiest ways are to either acquire a named mutex, or try to open a
socket on a port which nothing but your app would use. Of course, both
are problematic in terms of namespace - creating a name no-one else is
likely to use for a mutex is easier than working out a port number
which no-one else is likely to use though.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 13 '05 #2
A

"PalB" <pa*******@hotmail.com> wrote in message
news:Oo**************@TK2MSFTNGP10.phx.gbl...
How to stop running multiple instances of my App in C#?


I check to see if the program is already running in Main before the call to
the actual object to run it.

Of course this assumes that your program name is unique, therefore if you
have another application with the same Name, it won't run at all...

static void Main(){
if( System.Diagnostics.Process.GetProcessesByName(
"ProgramNameHere" ).Length > 1 ){
return;
}
}
Nov 13 '05 #3
Thanx a lot... i will chose the mutex part :)

Thanx again,
PalB

"Jon Skeet" <sk***@pobox.com> wrote in message
news:MP************************@news.microsoft.com ...
PalB <pa*******@hotmail.com> wrote:
How to stop running multiple instances of my App in C#?


The easiest ways are to either acquire a named mutex, or try to open a
socket on a port which nothing but your app would use. Of course, both
are problematic in terms of namespace - creating a name no-one else is
likely to use for a mutex is easier than working out a port number
which no-one else is likely to use though.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too

Nov 13 '05 #4
PalB <pa*******@hotmail.com> wrote:
Hi i am writing code like this.....is it ok?

static void Main()
{
bool isNew = false;
Mutex mtx = new Mutex( true, "MyApp_Mutex", out isNew );
if( !isNew )
{
MessageBox.Show( "MyApp is already running." );
return;
}
}


You don't need to specify the initial value for isNew - out parameters
don't need to be definitely assigned beforehand.

Other than that, it looks okay to me - have you tried it?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mandhare Prashant | last post by:
Hello, I have Mapoint software installed on my machine. Now, in VC++, I can use this mapoint application in my program as below- _Application mapapp; _Map map;
11
by: Clark Stevens | last post by:
I just finished a WinForms app in VB.NET. I want to allow the user to be able to run multiple instances of the program like you can with Notepad and Wordpad. The way it is now, once I run the...
6
by: Xenio | last post by:
Hi, I'd like to make sure that only one instance of my app is running per User Session. In addition this has to work with user rights and in a Windows 2k/2k3 and Citrix Terminalserver...
1
by: Vivek | last post by:
Hi, I am developing a MDI application. I need to track the child forms open so that I can stop a user from opening the multiple instances of the same child form. Now what is the best way of...
7
by: Rob | last post by:
I do not want multiple instances of a vb.net program running concurrently... How may I detect this ? Thanks
3
by: Michel | last post by:
Hi, I wrote an app in .Net and I whant only 1 instance of this app open for the user; the user open my app, do some works and try to open another instance of my app, I whant to show a message to...
1
by: sunil | last post by:
Hello All. I have written a program as an exe that performs some kind of order processing. The program is first configured and then started manually. I have have multiple instances of this...
6
by: Bishman | last post by:
I am sure this question has been asked many times before but can someone suggest a method of stopping two instances of a C# app running at the same time ? Preferably I would like an attempt to...
2
by: Sjoerd Op 't Land | last post by:
Hello all, I'm using threading for generating video content. The trouble is how to kill the thread, because there are multiple (simultaneous) owners of a thread. Ideally, a flag would be set...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.