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
Sign In
Register
AdSense Revenue
Active Members
Today
Nikhil Gaur
(70)
Shameer
(34)
Nadheera V
(30)
Last 7 Days
Nikhil Gaur
(621)
Anil Kumar ...
(582)
Abhisek Panda
(445)
more...
Resources
»
Articles
»
.NET Framework
»
How to restrict a program to a single instance
Posted Date: 01 Oct 2004
Resource Type:
Articles
Category:
.NET Framework
Author:
Vimal Kanth
Member Level:
Silver
Rating:
Points
: 5
Include System.Diagnostics namespace.
Create instance for Process class to store the current running process.
GetCurrentProcess() will create a new process component and assign it to the currnet process we are running.
Create another instance for Process class.Check whether already the same process in running using GetProcessesByName method.GetProcessesByName method creates an array of process and associates them with all the process component that share the specified process name.
Check if the length of the array object is greater than one.If it is then current process is already instantiated. Otherwise allow the process to run.
Here is the code :
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:
Venkatarajan Arthanari
01 Oct 2004
Member Level:
Silver
Points
: 0
Good article.
Venkatarajn
Lot to Learn,
Too Little Time.
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:
Model Driven Architecture (MDA)
Previous Resource:
Exploit .NET Support in Yukon
Return to Discussion Resource Index
Post New Resource
Category:
.NET Framework
Post resources and
earn money
!
Related Resources
Model Driven Architecture (MDA)
OverView of Assemblies
Event Log Creation
Calling Com Components from .Net Application
Difference b/w 'Dim obj as Emp' and Dim obj as New Emp
Singleton Class.
dotNet Slackers
About Us
Contact Us
Privacy Policy
Terms Of Use