473,405 Members | 2,344 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,405 software developers and data experts.

Prevent Openning the program twice

I made a gui program with c# but i want even if people double click my
program more than once it would only open once
is something like that possible if it is how?
Nov 17 '05 #1
9 15883
Ste
25/04/2005 9.17.52
Tolga Tanriverdi <to***@sylveria.gen.tr> wrote in message
<#M**************@TK2MSFTNGP15.phx.gbl>
I made a gui program with c# but i want even if people double click my program more than once it would only open once
is something like that possible if it is how?


I've used this class and worked fine..it is in vb.net, I hope this is
not a problem...
http://www.codeproject.com/vb/net/sing_inistan.asp
Nov 17 '05 #2
Process currentProcess = Process.GetCurrentProcess();
if(Process.GetProcessesByName(currentProcess.Proce ssName,
currentProcess.MachineName).Length>1)
{
Console.Write("Already running");
Console.Read();
}

Gabriel Lozano-Morán
Nov 17 '05 #3

"Tolga Tanriverdi" <to***@sylveria.gen.tr> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I made a gui program with c# but i want even if people double click my
program more than once it would only open once
is something like that possible if it is how?


Use a global mutex to identify your running instance.
This way you prevent running multiple instances machine wide.

bool freeToRun;
string safeName = "Global\\StringUniquelyIdentifyingThisApplication" ;
using(System.Threading.Mutex m = new System.Threading.Mutex(true, safeName
, out freeToRun))
{
if (freeToRun)
Application.Run (new MainForm());
MessageBox.Show("Already running...", safeName);
}

Willy.
Nov 17 '05 #4
Ste
25/04/2005 10.29.30
"LOZANO-MORÁN, Gabriel" <ga************@no-spam.com> wrote in message
<OO**************@TK2MSFTNGP14.phx.gbl>
Process currentProcess = Process.GetCurrentProcess();
if(Process.GetProcessesByName(currentProcess.Proce ssName,
currentProcess.MachineName).Length>1)
{
Console.Write("Already running");
Console.Read();
}

Gabriel Lozano-Morán


Gabriel, this is not a good way for several reasons (also MSDN
indicates this limits): it couldn't work due to limited user rights,
or if performance counters are disabled. The best solution is to use
mutex, as indicated by Willy...also in VB2005 implementation they use
mutex!
Nov 17 '05 #5
Tolga Tanriverdi <to***@sylveria.gen.tr> wrote:
I made a gui program with c# but i want even if people double click my
program more than once it would only open once
is something like that possible if it is how?


This is in the FAQ:
http://www.yoda.arachsys.com/csharp/...ation.instance
Nov 17 '05 #6
Aah so in the 2005 we can get Application Previous instance easier right?

"Ste" <no@no.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
25/04/2005 10.29.30
"LOZANO-MORÁN, Gabriel" <ga************@no-spam.com> wrote in message
<OO**************@TK2MSFTNGP14.phx.gbl>
Process currentProcess = Process.GetCurrentProcess();
if(Process.GetProcessesByName(currentProcess.Proce ssName,
currentProcess.MachineName).Length>1)
{
Console.Write("Already running");
Console.Read();
}

Gabriel Lozano-Morán


Gabriel, this is not a good way for several reasons (also MSDN
indicates this limits): it couldn't work due to limited user rights,
or if performance counters are disabled. The best solution is to use
mutex, as indicated by Willy...also in VB2005 implementation they use
mutex!

Nov 17 '05 #7

"kids_pro" <ki******@yahoo.com> wrote in message
news:ud**************@TK2MSFTNGP09.phx.gbl...
Aah so in the 2005 we can get Application Previous instance easier right?


Easier than what?

Willy.
Nov 17 '05 #8
Willy I think that what he is trying to say is that in VB6 we have
App.PrevInstance and it would be a nice addition to future versions of the
..NET base class library to have something similar.

Gabriel Lozano-Morán

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:#v**************@TK2MSFTNGP10.phx.gbl...

"kids_pro" <ki******@yahoo.com> wrote in message
news:ud**************@TK2MSFTNGP09.phx.gbl...
Aah so in the 2005 we can get Application Previous instance easier right?


Easier than what?

Willy.

Nov 17 '05 #9

"LOZANO-MORÁN, Gabriel" <ga************@no-spam.com> wrote in message
news:Oh**************@tk2msftngp13.phx.gbl...
Willy I think that what he is trying to say is that in VB6 we have
App.PrevInstance and it would be a nice addition to future versions of the
.NET base class library to have something similar.

Gabriel Lozano-Morán


The problem with App.PrevInstance is that it fails in a TS environment and
that it can't be used for non windows applications.

Willy.
Nov 17 '05 #10

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

Similar topics

1
by: G4Gun | last post by:
Hi, I have a form in which I have this link :- < href="javascript:submitform(parameters );"> . In the JavaScript function submitform, there is the code for submitting the form.Thi works fine with...
8
by: Dirk | last post by:
Hello, Can anyone tell me what the best way is to prevent an application from starting up twice. Thanks, Dirk
7
by: Douglas | last post by:
I have a frontend and backend database , program.mde and data.mdb on a client PC. How do i prevent them launching the program.mde more than once on a single PC? Somtimes they minizmise the program...
2
by: Paul Steele | last post by:
Are there any Windows hooks or Win32 API calls that would let a C# program log program launches?
2
by: yxq | last post by:
Hello How to detect that own program has been executed? Prevent to execute twice! Thanks
2
by: Totto | last post by:
Hi How do I prevent a program from beeing started more than one time. IE. If a dot net app is already started how do I prevent a second instance to be started ? Tnx Totto
0
by: gguan123 | last post by:
Recommend an excellent ASP program gives everyone:Webmaster club news system v5.09 demo:http://www.caifuw.com/en/new/ download:http://dow.caifuw.com/new5.09freeEn.rar Categories:asp(news system)...
41
by: c | last post by:
Hi every one, Me and my Cousin were talking about C and C#, I love C and he loves C#..and were talking C is ...blah blah...C# is Blah Blah ...etc and then we decided to write a program that...
0
by: lotus111 | last post by:
I am using the new visual basic 2008. I want to prevent the program from running twice if the user clicks on it more than once. Is there a setting for this? Or some other method?
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.