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
[color=blue]
>-----Original Message-----
>how do i prevent the second instance of my app from[/color]
being instanced when one[color=blue]
>is already running?
>
>
>.
>[/color]
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[MVP]" <dvravikanth@ho tmail.com> wrote in message
news:0b1e01c372 c1$82220cb0$a30 1280a@phx.gbl.. .[color=blue]
> 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]
>
>[color=green]
> >-----Original Message-----
> >how do i prevent the second instance of my app from[/color]
> being instanced when one[color=green]
> >is already running?
> >
> >
> >.
> >[/color][/color]
Ravikanth[MVP] <dvravikanth@ho tmail.com> wrote:[color=blue]
> 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[/color]
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.
Comment