473,324 Members | 2,400 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,324 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 15861
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.