Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
How to prevent two Processes running the Same Application
WhatsApp
Carmelo La Monica
Apr 25
2015
1.8
k
0
0
How to prevent two p
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Windows.Forms;
using
System.Threading;
namespace
MutexClassExample
{
static
class
Program
{
static
Mutex m;
/// <summary>
/// </summary>
[STAThread]
static
void
Main()
{
bool
first =
false
;
m =
new
Mutex(
true
, Application.ProductName.ToString(),
out
first);
if
((first))
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(
false
);
Application.Run(
new
Form1());
m.ReleaseMutex();
}
else
{
MessageBox.Show(
"Application"
+
" "
+ Application.ProductName.ToString() +
" "
+
"already running"
);
}
}
}
}
C#
Up Next
How to prevent two Processes running the Same Application