473,837 Members | 1,551 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to limit program can only run one instance.

Hi All,

How to limit the c# program can only run one instance at the same
time ?

Thank you!

Best regards,
Boki.

Jul 23 '07 #1
20 10650
"Boki Digtal" <bo******@ms21. hinet.netwrote in message news:11******** *************@x 35g2000prf.goog legroups.com...
How to limit the c# program can only run one instance at the same
time ?

using System.Threadin g;

bool blnFirstInstanc e;

using (Mutex objMutex = new Mutex(false, "Local\\" + "<app name>", out blnFirstInstanc e))
{
if (!blnFirstInsta nce)
{
MessageBox.Show ("<app nameis already running", "Single Use Only", MessageBoxButto ns.OK, MessageBoxIcon. Stop);
Application.Exi t();
}
else
{
Application.Run (new Form1()); // or whatever your startup is...
}
}
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Jul 23 '07 #2
On 7 23 , 6 11 , "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
"Boki Digtal" <bokit...@ms21. hinet.netwrote in messagenews:11* *************** *****@x35g2000p rf.googlegroups .com...
How to limit the c# program can only run one instance at the same
time ?

using System.Threadin g;

bool blnFirstInstanc e;

using (Mutex objMutex = new Mutex(false, "Local\\" + "<app name>", out blnFirstInstanc e))
{
if (!blnFirstInsta nce)
{
MessageBox.Show ("<app nameis already running", "Single Use Only", MessageBoxButto ns.OK, MessageBoxIcon. Stop);
Application.Exi t();
}
else
{
Application.Run (new Form1()); // or whatever your startup is...
}

}

--
Mark Rae
ASP.NET MVPhttp://www.markrae.net
Great, thanks!

Boki.

Jul 24 '07 #3
On 7 24 , 2 27 , Boki Digtal <bokit...@ms21. hinet.netwrote:
On 7 23 , 6 11 , "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
"Boki Digtal" <bokit...@ms21. hinet.netwrote in messagenews:11* *************** *****@x35g2000p rf.googlegroups .com...
How to limit the c# program can only run one instance at the same
time ?
using System.Threadin g;
bool blnFirstInstanc e;
using (Mutex objMutex = new Mutex(false, "Local\\" + "<app name>", out blnFirstInstanc e))
{
if (!blnFirstInsta nce)
{
MessageBox.Show ("<app nameis already running", "Single Use Only", MessageBoxButto ns.OK, MessageBoxIcon. Stop);
Application.Exi t();
}
else
{
Application.Run (new Form1()); // or whatever your startup is...
}
}
--
Mark Rae
ASP.NET MVPhttp://www.markrae.net

Great, thanks!

Boki.
Is there any easier way like OnlyOneInstance = ture;

Thanks :)

Boki.

Jul 30 '07 #4
"Boki Digtal" <bo******@ms21. hinet.netwrote in message
news:11******** *************@i 38g2000prf.goog legroups.com...
using System.Threadin g;
bool blnFirstInstanc e;
using (Mutex objMutex = new Mutex(false, "Local\\" + "<app name>", out
blnFirstInstanc e))
{
if (!blnFirstInsta nce)
{
MessageBox.Show ("<app nameis already running", "Single Use
Only", MessageBoxButto ns.OK, MessageBoxIcon. Stop);
Application.Exi t();
}
else
{
Application.Run (new Form1()); // or whatever your startup
is...
}
}

Great, thanks!

Is there any easier way like OnlyOneInstance = ture;
An easier way? The above is only a dozen lines of code...

Can't you get it to work, then...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 30 '07 #5
On 7 30 , 1 51 , "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
"Boki Digtal" <bokit...@ms21. hinet.netwrote in message

news:11******** *************@i 38g2000prf.goog legroups.com...
using System.Threadin g;
bool blnFirstInstanc e;
using (Mutex objMutex = new Mutex(false, "Local\\" + "<app name>", out
blnFirstInstanc e))
{
if (!blnFirstInsta nce)
{
MessageBox.Show ("<app nameis already running", "Single Use
Only", MessageBoxButto ns.OK, MessageBoxIcon. Stop);
Application.Exi t();
}
else
{
Application.Run (new Form1()); // or whatever your startup
is...
}
}
Great, thanks!
Is there any easier way like OnlyOneInstance = ture;

An easier way? The above is only a dozen lines of code...

Can't you get it to work, then...?

--
Mark Rae
ASP.NET MVPhttp://www.markrae.net
Sorry, in fact, I don't have try it yet.

If I recall correctly, there is a setting in VC6, when we assign so
many parameters to create a form. For this purpose, what we need to do
is assign a parameter as true only.

I believe your code can work, but I am just curious if there is any
other methods.

:)

Thanks!

Best regards,
Boki.

Jul 30 '07 #6
On Jul 30, 8:15 am, Boki Digtal <bokit...@ms21. hinet.netwrote:
Sorry, in fact, I don't have try it yet.

If I recall correctly, there is a setting in VC6, when we assign so
many parameters to create a form. For this purpose, what we need to do
is assign a parameter as true only.

I believe your code can work, but I am just curious if there is any
other methods.
You could add a reference to the Microsoft.Visua lBasic assembly and
use the WindowsFormsApp licationBase class which I believe has this
sort of functionality. I don't know much about it, but it *might* make
things easier for you.

Jon

Jul 30 '07 #7
On 7 30 , 3 26 , "Jon Skeet [C# MVP]" <sk...@pobox.co mwrote:
On Jul 30, 8:15 am, Boki Digtal <bokit...@ms21. hinet.netwrote:
Sorry, in fact, I don't have try it yet.
If I recall correctly, there is a setting in VC6, when we assign so
many parameters to create a form. For this purpose, what we need to do
is assign a parameter as true only.
I believe your code can work, but I am just curious if there is any
other methods.

You could add a reference to the Microsoft.Visua lBasic assembly and
use the WindowsFormsApp licationBase class which I believe has this
sort of functionality. I don't know much about it, but it *might* make
things easier for you.

Jon
visual basic ... ? but I am using c# ...

Boki.

Jul 30 '07 #8
"Boki Digtal" <bo******@ms21. hinet.netwrote in message
news:11******** **************@ j4g2000prf.goog legroups.com...
On 7 30 , 3 26 , "Jon Skeet [C# MVP]" <sk...@pobox.co mwrote:
>On Jul 30, 8:15 am, Boki Digtal <bokit...@ms21. hinet.netwrote:
Sorry, in fact, I don't have try it yet.
If I recall correctly, there is a setting in VC6, when we assign so
many parameters to create a form. For this purpose, what we need to do
is assign a parameter as true only.
I believe your code can work, but I am just curious if there is any
other methods.

You could add a reference to the Microsoft.Visua lBasic assembly and
use the WindowsFormsApp licationBase class which I believe has this
sort of functionality. I don't know much about it, but it *might* make
things easier for you.

Jon

visual basic ... ? but I am using c# ...
Yes, but you can set a reference to the Microsoft.Visua lBasic assembly and
use the (without wishing to get into a language war) "hand-holding"
functions ported over from VB6 if the code I suggested (which I pretty much
nicked from Jon anyway) is too much for you...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 30 '07 #9
On 7 30 , 4 18 , "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
"Boki Digtal" <bokit...@ms21. hinet.netwrote in message

news:11******** **************@ j4g2000prf.goog legroups.com...
On 7 30 , 3 26 , "Jon Skeet [C# MVP]" <sk...@pobox.co mwrote:
On Jul 30, 8:15 am, Boki Digtal <bokit...@ms21. hinet.netwrote:
Sorry, in fact, I don't have try it yet.
If I recall correctly, there is a setting in VC6, when we assign so
many parameters to create a form. For this purpose, what we need to do
is assign a parameter as true only.
I believe your code can work, but I am just curious if there is any
other methods.
You could add a reference to the Microsoft.Visua lBasic assembly and
use the WindowsFormsApp licationBase class which I believe has this
sort of functionality. I don't know much about it, but it *might* make
things easier for you.
Jon
visual basic ... ? but I am using c# ...

Yes, but you can set a reference to the Microsoft.Visua lBasic assembly and
use the (without wishing to get into a language war) "hand-holding"
functions ported over from VB6 if the code I suggested (which I pretty much
nicked from Jon anyway) is too much for you...

--
Mark Rae
ASP.NET MVPhttp://www.markrae.net
OK, got it, thanks :)

Boki.

Jul 30 '07 #10

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

Similar topics

4
2645
by: Bloon | last post by:
I have a question that how to debug a program only having .exe file. Is there any techniques or tools that can do that? Thanks a lot.
4
1973
by: grocery_stocker | last post by:
#include <iostream> //for cin and cout #include <iomanip> // for setw() #include <string> // for strlen() strcmp() strrev() #include <fstream> //ifstream and ofstream: file (input & output) #include <stdlib.h> //for system calls using namespace std; //functions will go here!! unsigned int count_vowels(char *pointer); int main(void)
3
3512
by: Vikrant | last post by:
Friends, Due an application (old) install program problem, Under AIX I could only create DB2 instance, I could also catalog it. Its complex application and I am not expert in creating full database for this application, but I have desired DB2 backup (by db2 backup db command). Can I do redirected restore (SET TABLESPACE CONTAINERS ....) only when instance is created & cataloged , I am under the impression that redirected restore is...
4
7103
by: Josh Burkard | last post by:
Hello How can i control, that a user can't start my VB.Net-Program 2 ore more times at once (maybee like Outlook)? At same time Parameters which are transfered with the second program should be transfered to the first program. Best regards Josh
1
2842
by: Shisou | last post by:
I think the title says it all... i'm building a program that will read in a dictionary and then ask the user for a string and will check all permutations of the string against the dictionary to see if it's a word. but for some reason when i run the program normally it crashes out... but if i run it in debug mode it runs fine... This is the code it gets stuck at wordList = (char**)malloc(num * sizeof(char*)); for(i=0;i<num;i++){...
0
10863
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10609
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10263
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9390
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6987
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5663
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5838
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4034
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3120
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.