TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
How to prevent two Processes running the Same Application
Carmelo La Monica
Apr 25
2015
Code
1.7
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
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#