473,394 Members | 1,702 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,394 software developers and data experts.

Limit C# Windows Application to single instance

Hi,

Is there an easy way to limit a .NET application to a
single running instance, ala like checking the
hPrevInstance in MFC? October 2003 MSDN only has old
samples that use named mutexes; is there anything more
slick in .NET??

--Richard
Nov 15 '05 #1
5 6187
Check out the tools, in the Genghis project

http://www.genghisgroup.com

It already has a class that does it for you.

I think the way it was implemented was pretty "slick".

Regards
Brian W
"Richard" <an*******@discussions.microsoft.com> wrote in message
news:6f****************************@phx.gbl...
Hi,

Is there an easy way to limit a .NET application to a
single running instance, ala like checking the
hPrevInstance in MFC? October 2003 MSDN only has old
samples that use named mutexes; is there anything more
slick in .NET??

--Richard

Nov 15 '05 #2
Have a look at the tips at www.buygold.net . Once of tips does this and sends the command line to the previous instance.

--
Michael Culley
"Richard" <an*******@discussions.microsoft.com> wrote in message news:6f****************************@phx.gbl...
Hi,

Is there an easy way to limit a .NET application to a
single running instance, ala like checking the
hPrevInstance in MFC? October 2003 MSDN only has old
samples that use named mutexes; is there anything more
slick in .NET??

--Richard

Nov 15 '05 #3
n!
> Is there an easy way to limit a .NET application to a
single running instance, ala like checking the
hPrevInstance in MFC? October 2003 MSDN only has old
samples that use named mutexes; is there anything more
slick in .NET??


Here's another link:

http://www.bobpowell.net/singleinstance.htm

n!
Nov 15 '05 #4
Hi,

I use the following method. When true is returned I exit immediately.

private bool PreviousInstance()
{
return ( System.Diagnostics.Process.GetProcessesByName(
System.Diagnostics.Process.GetCurrentProcess().Pro cessName ).Length > 1 );
}

Marcello
Nov 15 '05 #5
Try this :
using System.Diagnostics;

static void Main(string[] cmdLine )
{
Process[] myProcess = Process.GetProcessesByName("YourAppName");

if ( myProcess.Length > 1 )
{
MessageBox.Show( "The application is already launched...");
}
else
{
// Application Execution...

}
}

In article <6f****************************@phx.gbl>,
an*******@discussions.microsoft.com says...
Hi,

Is there an easy way to limit a .NET application to a
single running instance, ala like checking the
hPrevInstance in MFC? October 2003 MSDN only has old
samples that use named mutexes; is there anything more
slick in .NET??

--Richard

Nov 15 '05 #6

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

Similar topics

4
by: Leandro | last post by:
There is an upper memory limit in Python? I have 2GB RAM and 2 processors Xeon 2.4 - (Windows XP), but I just can use 1.2G of memory, after this python crashes. Does someone know if python has...
11
by: KalleD | last post by:
Hi, I need to use a lot of memory in an aplication. But I get OutOfMemoryException whenever I try to allocate more than around 1.2GB. Ex: byte c=new byte; My computer (win xp) have 4GB of RAM...
2
by: Alper AKCAYOZ | last post by:
Hello, I have developped an application used by Windows Forms (.NET) at Visual C++ ..NET v2003. I would like to limit my application to one instance working at a moment. More than one working...
4
by: GrandpaB | last post by:
Hi, I am attempting to limit an application so that the user cannot open a second instance of the application. Any clues? Thanks, -- GrandpaB
2
by: deko | last post by:
When to use a privileged user thread rather than a windows service? That's the question raised in a previous post . It was suggested that if the service needs to interact with a WinForms app...
16
by: google | last post by:
Hello, I am working on an Acc2003 app for my company. In the interest of reducing chances of corruption due to unstable network connectivity, I would like to either prevent users from running it...
3
by: sadanjan | last post by:
Hi , Appreciate if someone can clarify if database Share Memory Limit (2 GB ) in Unix 32 bit boxes is the top limit for all the databases put together in a database or is it for each of the...
20
by: Boki Digtal | last post by:
Hi All, How to limit the c# program can only run one instance at the same time ? Thank you! Best regards, Boki.
8
by: JS | last post by:
Using Visual Studio 2008 I want to prevent myconsoleapp.exe from executing multiple times on a given Windows host. The desire is, if a user launches myconsoleapp.exe a second time the second...
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: 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...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.