second instance

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Shawn

    #1

    second instance

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


  • Ravikanth[MVP]

    #2
    second instance

    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:


    Ravikanth[MVP]

    [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]

    Comment

    • Kieran Benton

      #3
      Re: second instance

      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[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]


      Comment

      • Jon Skeet

        #4
        Re: second instance

        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.

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

        --
        Jon Skeet - <skeet@pobox.co m>
        Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

        If replying to the group, please do not mail me too

        Comment

        Working...