C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Application windows, menus & toolbars »

Prevent Duplication of Exe in Windows Applciation


Posted Date: 10 May 2009    Resource Type: Code Snippets    Category: Application windows, menus & toolbars
Author: Deepika HaridasMember Level: Diamond    
Rating: 1 out of 5Points: 10



Sample code which will prevent your exe from being opened multiple times.

Include this namespace : using System.Threading;


static void Main()
{
string proc = Process.GetCurrentProcess().ProcessName;
Process[] prcs = Process.GetProcessesByName(proc);
if (prcs.Length > 1)
{
MessageBox.Show("Application is already running.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
}




Responses

Author: greeny_1984    11 May 2009Member Level: Diamond   Points : 1
Hi,

Nice piece of information

easily understandable

regards,

greeny_1984


Author: Aaditya Sharma    19 Jun 2009Member Level: Gold   Points : 0
good code snippet..very helpful..


Author: Viji RAJKUMAR    19 Jun 2009Member Level: Diamond   Points : 2
Hi,

The simplest way is to use Mutex.

use the System.Threading.Mutex class

Put this code in the entry point of your program

Dim mut As System.Threading.Mutex = New System.Threading.Mutex(False, Application.ProductName)

Dim running As Boolean = Not mut.WaitOne(0, False)

'If already running

If running Then
Application.ExitThread()
Return
End If



Author: Chitra_19    19 Jun 2009Member Level: Gold   Points : 0
Hi,

Good piece of code..

Very helpful..

Regards,
Chitra


Author: Deepika Haridas    20 Jun 2009Member Level: Diamond   Points : 1
Hi,

Thanks for your valuable comments..

Please do RATE if its useful.

And Viji thanks for adding second method too..
It good when all solutions are at one place.

Keep contributing!!

Regards,
Deepika


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Windows  .  Threading  .  Mutiple  .  IPhone  .  Exe  .  Difference  .  ASP.Net  .  ASP  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Text 2 Speak in VB.Net
Previous Resource: Dialog box creation using java.
Return to Discussion Resource Index
Post New Resource
Category: Application windows, menus & toolbars


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use