This simple code example uses the class Mutex, which tests the many processes of an application that are executed. Provides a simple demonstration example in the Program.cs file and enter the code to prevent them being carried out two processes of the same application, then compile the project and start the application twice from the executable on the compilation. In the beginning start the application will start regularly, instead trying to start a new job in the same application you will see a message indicating that the application is already running.
But now we see how to use it in this example. Runs in the Program.cs file verification by the Mutex class.
- 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>
- /// Main entry point of the application.
- /// </ Summary>
- [STAThread]
- static void Main()
- {
- bool first = false;
- m = new Mutex(true, Application.ProductName.ToString(), first - out);
- if((first))
- {
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new Form1());
- m.ReleaseMutex();
- }
- else
- {
- MessageBox.Show("Application" + "" + Application.ProductName.ToString() + "" + "already running");
- }
- }
- }
- }

Humayun Kabir MamunPosted Nov 3, 2015, 12:43 AM
Nice...
Gowtham KPosted Nov 2, 2015, 11:21 AM
Good One
Sibeesh VenuPosted Nov 2, 2015, 4:43 AM
Nice Share
Harshad PansuriyaPosted Nov 2, 2015, 12:32 AM
Nice one