second instance

  • Thread starter Thread starter Shawn
  • Start date Start date
S

Shawn

how do i prevent the second instance of my app from being instanced when one
is already running?
 
Hi

Singleton assures that there is one and only one instance
of the class and provides a global point of access to
it.There are number of cases in programming where you
need to make sure that there can be one and only one
instance of a class e.g Window Manager,Print Spooler etc.

you can use a private constructor to prevent programmers
from creating instances of Singleton

Check out the following article:
http://www.dotnetextreme.com/code/SingletonCs.asp

Ravikanth[MVP]
 
Ravikanth,

I think Shawn is trying to prevent a second instance of his "Program"
running. To do this it is common to obtain a exclusive lock on a file or
other shared resource when a program starts, and check to see if it is
possible (i.e. no other instance of the app has already obtained the lock).

Hope this helps,
Kieran
 
Ravikanth said:
Singleton assures that there is one and only one instance
of the class and provides a global point of access to
it.There are number of cases in programming where you
need to make sure that there can be one and only one
instance of a class e.g Window Manager,Print Spooler etc.

you can use a private constructor to prevent programmers
from creating instances of Singleton

Check out the following article:
http://www.dotnetextreme.com/code/SingletonCs.asp

Kieran has pointed out why this isn't actually useful in this case, but
I'd also like the say that the article you reference doesn't give a
thread-safe implementation of Singleton. There are much better ways of
implementing it.

See http://www.pobox.com/~skeet/csharp/singleton.html
 
Back
Top