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 » Articles » .NET Framework »

How to restrict a program to a single instance


Posted Date: 03 Aug 2004    Resource Type: Articles    Category: .NET Framework
Author: Muralidharan RamakrishnanMember Level: Gold    
Rating: 1 out of 5Points: 10



Introduction

This code piece demonstrates how to ensure only one instance of your application is running

In the program's main form, change the Main method to the following:

static void Main()
{
Process ThisProcess = Process.GetCurrentProcess();

Process [] AllProcesses = Process.GetProcessesByName(ThisProcess.ProcessName);

if (AllProcesses.Length > 1)
{
MessageBox.Show(ThisProcess.ProcessName + " is already running",
ThisProcess.ProcessName,
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
else
{
Application.Run(new MainForm());
}
}




Responses

Author: rakmrish    17 Aug 2004Member Level: Bronze   Points : 0
What namespace to be included if u want use Process class . how to use Process class in c#.net


Author: Muralidharan Ramakrishnan    17 Aug 2004Member Level: Gold   Points : 0
Hi the name space is System.Diagnostics.Process. You can use the same code with c# syntax for process class.


Author: Irfan Patel    23 Aug 2004Member Level: Silver   Points : 0
This article has already been written a few days back. Infact its just three article back in the list.
Please check out the following for a great discussion with other members on what are the pros and cons of the above code.
http://www.dotnetspider.com/Technology/KBPages/631.aspx


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

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: Difference Between vb.net and vb
Previous Resource: How to load Assemblies dynamically using Reflection
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use