Single instance of an object between different processes?

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

    Single instance of an object between different processes?

    Hi,

    I have an application that is made up of several executables. I need all
    these executables to use the same instance of an object.

    What is the best, most efficient way to approach this?

    Thanks a lot!


  • Brian Delahunty

    #2
    RE: Single instance of an object between different processes?

    Read up on Mutex's or check out this article on the CodeProject which
    explains how to do it:



    Hope this helps.

    --
    Brian Delahunty
    Ireland



    INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup I
    started in the southeast of Ireland.


    "Elad" wrote:
    [color=blue]
    > Hi,
    >
    > I have an application that is made up of several executables. I need all
    > these executables to use the same instance of an object.
    >
    > What is the best, most efficient way to approach this?
    >
    > Thanks a lot!
    >
    >
    >[/color]

    Comment

    • Octavio Hernandez

      #3
      Re: Single instance of an object between different processes?

      Hi,

      You can create a (static) class and expose the object as a static member of
      this class:

      public static class Globals // 'static' here only valid in C# 2.0
      {
      // the "global" instance
      private static TheClass theObject;
      // a public property that exposes the instance
      public static TheClass TheObject { get { return theObject; } }
      // class constructor - executed when class is loaded
      Globals()
      {
      // create and initialize "global" instance
      theObject = new TheClass();
      // etc.
      }
      }

      Applications can reference this object by Globals.TheObje ct.

      Regards - Octavio

      "Elad" <EladZZZ7690@ho tZZZmail.com> escribió en el mensaje
      news:Ob3If%23Xo FHA.2472@tk2msf tngp13.phx.gbl. ..[color=blue]
      > Hi,
      >
      > I have an application that is made up of several executables. I need all
      > these executables to use the same instance of an object.
      >
      > What is the best, most efficient way to approach this?
      >
      > Thanks a lot!
      >[/color]


      Comment

      • Vadym Stetsyak

        #4
        Re: Single instance of an object between different processes?

        You can also use remoting here, and use the object in the singletone
        instantiation pattern

        --
        Vadym Stetsyak aka Vadmyst

        "Brian Delahunty" <BrianDelahunty @discussions.mi crosoft.com> wrote in
        message news:6FF63B5C-8C82-444F-9C89-9678ADB0224B@mi crosoft.com...[color=blue]
        > Read up on Mutex's or check out this article on the CodeProject which
        > explains how to do it:
        >
        > http://www.codeproject.com/csharp/singleinstance.asp
        >
        > Hope this helps.
        >
        > --
        > Brian Delahunty
        > Ireland
        >
        > http://briandela.com/blog
        >
        > INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup I
        > started in the southeast of Ireland.
        >
        >
        > "Elad" wrote:
        >[color=green]
        > > Hi,
        > >
        > > I have an application that is made up of several executables. I need[/color][/color]
        all[color=blue][color=green]
        > > these executables to use the same instance of an object.
        > >
        > > What is the best, most efficient way to approach this?
        > >
        > > Thanks a lot!
        > >
        > >
        > >[/color][/color]


        Comment

        • Elad

          #5
          Re: Single instance of an object between different processes?

          Hi all, thanks for your replies.

          I may have done a poor job of explaining myself.

          I wish to use a single instance of an object across different AppDomains. I
          do not need to verify whether an EXE application already has an instance
          running. The singleton pattern does not apply for multiple AppDomains,
          since it is an in-process pattern.

          I believe my only choices are Remoting and WebServices. Am I wrong?

          Thanks again.


          "Vadym Stetsyak" <vadym_s@ukr.ne t> wrote in message
          news:OLP3qcYoFH A.1872@TK2MSFTN GP10.phx.gbl...[color=blue]
          > You can also use remoting here, and use the object in the singletone
          > instantiation pattern
          >
          > --
          > Vadym Stetsyak aka Vadmyst
          >
          > "Brian Delahunty" <BrianDelahunty @discussions.mi crosoft.com> wrote in
          > message news:6FF63B5C-8C82-444F-9C89-9678ADB0224B@mi crosoft.com...[color=green]
          >> Read up on Mutex's or check out this article on the CodeProject which
          >> explains how to do it:
          >>
          >> http://www.codeproject.com/csharp/singleinstance.asp
          >>
          >> Hope this helps.
          >>
          >> --
          >> Brian Delahunty
          >> Ireland
          >>
          >> http://briandela.com/blog
          >>
          >> INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup I
          >> started in the southeast of Ireland.
          >>
          >>
          >> "Elad" wrote:
          >>[color=darkred]
          >> > Hi,
          >> >
          >> > I have an application that is made up of several executables. I need[/color][/color]
          > all[color=green][color=darkred]
          >> > these executables to use the same instance of an object.
          >> >
          >> > What is the best, most efficient way to approach this?
          >> >
          >> > Thanks a lot!
          >> >
          >> >
          >> >[/color][/color]
          >
          >[/color]


          Comment

          • Oliver Sturm

            #6
            Re: Single instance of an object between different processes?

            Elad wrote:
            [color=blue]
            > I wish to use a single instance of an object across different AppDomains. I
            > do not need to verify whether an EXE application already has an instance
            > running. The singleton pattern does not apply for multiple AppDomains,
            > since it is an in-process pattern.
            >
            > I believe my only choices are Remoting and WebServices. Am I wrong?[/color]

            I don't think web services are going to be a good way for you to go, if
            I understand your situation correctly. Remoting will probably be a good
            idea. There's a good article by Ingo Rammer at

            which compares different Remoting use cases, and there are also hints at
            competing technologies if you should find that Remoting is not right for
            you after all.



            Oliver Sturm
            --
            omnibus ex nihilo ducendis sufficit unum
            Spaces inserted to prevent google email destruction:
            MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
            ICQ 27142619 http://www.sturmnet.org/blog

            Comment

            • Brian Delahunty

              #7
              Re: Single instance of an object between different processes?

              Elad,

              The example I posted above on the CodeProject shows how to do this using
              Mutexs.

              Brian

              --
              Brian Delahunty
              Ireland



              INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup I
              started in the southeast of Ireland.


              "Elad" wrote:
              [color=blue]
              > Hi all, thanks for your replies.
              >
              > I may have done a poor job of explaining myself.
              >
              > I wish to use a single instance of an object across different AppDomains. I
              > do not need to verify whether an EXE application already has an instance
              > running. The singleton pattern does not apply for multiple AppDomains,
              > since it is an in-process pattern.
              >
              > I believe my only choices are Remoting and WebServices. Am I wrong?
              >
              > Thanks again.
              >
              >
              > "Vadym Stetsyak" <vadym_s@ukr.ne t> wrote in message
              > news:OLP3qcYoFH A.1872@TK2MSFTN GP10.phx.gbl...[color=green]
              > > You can also use remoting here, and use the object in the singletone
              > > instantiation pattern
              > >
              > > --
              > > Vadym Stetsyak aka Vadmyst
              > >
              > > "Brian Delahunty" <BrianDelahunty @discussions.mi crosoft.com> wrote in
              > > message news:6FF63B5C-8C82-444F-9C89-9678ADB0224B@mi crosoft.com...[color=darkred]
              > >> Read up on Mutex's or check out this article on the CodeProject which
              > >> explains how to do it:
              > >>
              > >> http://www.codeproject.com/csharp/singleinstance.asp
              > >>
              > >> Hope this helps.
              > >>
              > >> --
              > >> Brian Delahunty
              > >> Ireland
              > >>
              > >> http://briandela.com/blog
              > >>
              > >> INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup I
              > >> started in the southeast of Ireland.
              > >>
              > >>
              > >> "Elad" wrote:
              > >>
              > >> > Hi,
              > >> >
              > >> > I have an application that is made up of several executables. I need[/color]
              > > all[color=darkred]
              > >> > these executables to use the same instance of an object.
              > >> >
              > >> > What is the best, most efficient way to approach this?
              > >> >
              > >> > Thanks a lot!
              > >> >
              > >> >
              > >> >[/color]
              > >
              > >[/color]
              >
              >
              >[/color]

              Comment

              • Elad

                #8
                Re: Single instance of an object between different processes?

                Brian, thanks for your help...

                Maybe I'm missing something: How can mutexes help me if I require a single
                instance of a generic class (not a single instance of a process) throughout
                a single machine...


                "Brian Delahunty" <BrianDelahunty @discussions.mi crosoft.com> wrote in
                message news:DD096477-996B-4013-9680-8587F15543B3@mi crosoft.com...[color=blue]
                > Elad,
                >
                > The example I posted above on the CodeProject shows how to do this using
                > Mutexs.
                >
                > Brian
                >
                > --
                > Brian Delahunty
                > Ireland
                >
                > http://briandela.com/blog
                >
                > INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup I
                > started in the southeast of Ireland.
                >
                >
                > "Elad" wrote:
                >[color=green]
                >> Hi all, thanks for your replies.
                >>
                >> I may have done a poor job of explaining myself.
                >>
                >> I wish to use a single instance of an object across different AppDomains.
                >> I
                >> do not need to verify whether an EXE application already has an instance
                >> running. The singleton pattern does not apply for multiple AppDomains,
                >> since it is an in-process pattern.
                >>
                >> I believe my only choices are Remoting and WebServices. Am I wrong?
                >>
                >> Thanks again.
                >>
                >>
                >> "Vadym Stetsyak" <vadym_s@ukr.ne t> wrote in message
                >> news:OLP3qcYoFH A.1872@TK2MSFTN GP10.phx.gbl...[color=darkred]
                >> > You can also use remoting here, and use the object in the singletone
                >> > instantiation pattern
                >> >
                >> > --
                >> > Vadym Stetsyak aka Vadmyst
                >> >
                >> > "Brian Delahunty" <BrianDelahunty @discussions.mi crosoft.com> wrote in
                >> > message news:6FF63B5C-8C82-444F-9C89-9678ADB0224B@mi crosoft.com...
                >> >> Read up on Mutex's or check out this article on the CodeProject which
                >> >> explains how to do it:
                >> >>
                >> >> http://www.codeproject.com/csharp/singleinstance.asp
                >> >>
                >> >> Hope this helps.
                >> >>
                >> >> --
                >> >> Brian Delahunty
                >> >> Ireland
                >> >>
                >> >> http://briandela.com/blog
                >> >>
                >> >> INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup
                >> >> I
                >> >> started in the southeast of Ireland.
                >> >>
                >> >>
                >> >> "Elad" wrote:
                >> >>
                >> >> > Hi,
                >> >> >
                >> >> > I have an application that is made up of several executables. I
                >> >> > need
                >> > all
                >> >> > these executables to use the same instance of an object.
                >> >> >
                >> >> > What is the best, most efficient way to approach this?
                >> >> >
                >> >> > Thanks a lot!
                >> >> >
                >> >> >
                >> >> >
                >> >
                >> >[/color]
                >>
                >>
                >>[/color][/color]


                Comment

                • Brian Delahunty

                  #9
                  Re: Single instance of an object between different processes?

                  lol. Sorry, I misread your post...! Silly me.
                  --
                  Brian Delahunty
                  Ireland



                  INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup I
                  started in the southeast of Ireland.


                  "Elad" wrote:
                  [color=blue]
                  > Brian, thanks for your help...
                  >
                  > Maybe I'm missing something: How can mutexes help me if I require a single
                  > instance of a generic class (not a single instance of a process) throughout
                  > a single machine...
                  >
                  >
                  > "Brian Delahunty" <BrianDelahunty @discussions.mi crosoft.com> wrote in
                  > message news:DD096477-996B-4013-9680-8587F15543B3@mi crosoft.com...[color=green]
                  > > Elad,
                  > >
                  > > The example I posted above on the CodeProject shows how to do this using
                  > > Mutexs.
                  > >
                  > > Brian
                  > >
                  > > --
                  > > Brian Delahunty
                  > > Ireland
                  > >
                  > > http://briandela.com/blog
                  > >
                  > > INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup I
                  > > started in the southeast of Ireland.
                  > >
                  > >
                  > > "Elad" wrote:
                  > >[color=darkred]
                  > >> Hi all, thanks for your replies.
                  > >>
                  > >> I may have done a poor job of explaining myself.
                  > >>
                  > >> I wish to use a single instance of an object across different AppDomains.
                  > >> I
                  > >> do not need to verify whether an EXE application already has an instance
                  > >> running. The singleton pattern does not apply for multiple AppDomains,
                  > >> since it is an in-process pattern.
                  > >>
                  > >> I believe my only choices are Remoting and WebServices. Am I wrong?
                  > >>
                  > >> Thanks again.
                  > >>
                  > >>
                  > >> "Vadym Stetsyak" <vadym_s@ukr.ne t> wrote in message
                  > >> news:OLP3qcYoFH A.1872@TK2MSFTN GP10.phx.gbl...
                  > >> > You can also use remoting here, and use the object in the singletone
                  > >> > instantiation pattern
                  > >> >
                  > >> > --
                  > >> > Vadym Stetsyak aka Vadmyst
                  > >> >
                  > >> > "Brian Delahunty" <BrianDelahunty @discussions.mi crosoft.com> wrote in
                  > >> > message news:6FF63B5C-8C82-444F-9C89-9678ADB0224B@mi crosoft.com...
                  > >> >> Read up on Mutex's or check out this article on the CodeProject which
                  > >> >> explains how to do it:
                  > >> >>
                  > >> >> http://www.codeproject.com/csharp/singleinstance.asp
                  > >> >>
                  > >> >> Hope this helps.
                  > >> >>
                  > >> >> --
                  > >> >> Brian Delahunty
                  > >> >> Ireland
                  > >> >>
                  > >> >> http://briandela.com/blog
                  > >> >>
                  > >> >> INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup
                  > >> >> I
                  > >> >> started in the southeast of Ireland.
                  > >> >>
                  > >> >>
                  > >> >> "Elad" wrote:
                  > >> >>
                  > >> >> > Hi,
                  > >> >> >
                  > >> >> > I have an application that is made up of several executables. I
                  > >> >> > need
                  > >> > all
                  > >> >> > these executables to use the same instance of an object.
                  > >> >> >
                  > >> >> > What is the best, most efficient way to approach this?
                  > >> >> >
                  > >> >> > Thanks a lot!
                  > >> >> >
                  > >> >> >
                  > >> >> >
                  > >> >
                  > >> >
                  > >>
                  > >>
                  > >>[/color][/color]
                  >
                  >
                  >[/color]

                  Comment

                  • Brian Delahunty

                    #10
                    Re: Single instance of an object between different processes?

                    You could use remoting or use a Singleton class that derives from
                    MarshalByRef and then you could keep that in a named appdomain. You then just
                    marshal the singleton from that appdomain into the one you are using and then
                    access the underlying object.


                    --
                    Brian Delahunty
                    Ireland



                    INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup I
                    started in the southeast of Ireland.


                    "Elad" wrote:
                    [color=blue]
                    > Hi all, thanks for your replies.
                    >
                    > I may have done a poor job of explaining myself.
                    >
                    > I wish to use a single instance of an object across different AppDomains. I
                    > do not need to verify whether an EXE application already has an instance
                    > running. The singleton pattern does not apply for multiple AppDomains,
                    > since it is an in-process pattern.
                    >
                    > I believe my only choices are Remoting and WebServices. Am I wrong?
                    >
                    > Thanks again.
                    >
                    >
                    > "Vadym Stetsyak" <vadym_s@ukr.ne t> wrote in message
                    > news:OLP3qcYoFH A.1872@TK2MSFTN GP10.phx.gbl...[color=green]
                    > > You can also use remoting here, and use the object in the singletone
                    > > instantiation pattern
                    > >
                    > > --
                    > > Vadym Stetsyak aka Vadmyst
                    > >
                    > > "Brian Delahunty" <BrianDelahunty @discussions.mi crosoft.com> wrote in
                    > > message news:6FF63B5C-8C82-444F-9C89-9678ADB0224B@mi crosoft.com...[color=darkred]
                    > >> Read up on Mutex's or check out this article on the CodeProject which
                    > >> explains how to do it:
                    > >>
                    > >> http://www.codeproject.com/csharp/singleinstance.asp
                    > >>
                    > >> Hope this helps.
                    > >>
                    > >> --
                    > >> Brian Delahunty
                    > >> Ireland
                    > >>
                    > >> http://briandela.com/blog
                    > >>
                    > >> INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup I
                    > >> started in the southeast of Ireland.
                    > >>
                    > >>
                    > >> "Elad" wrote:
                    > >>
                    > >> > Hi,
                    > >> >
                    > >> > I have an application that is made up of several executables. I need[/color]
                    > > all[color=darkred]
                    > >> > these executables to use the same instance of an object.
                    > >> >
                    > >> > What is the best, most efficient way to approach this?
                    > >> >
                    > >> > Thanks a lot!
                    > >> >
                    > >> >
                    > >> >[/color]
                    > >
                    > >[/color]
                    >
                    >
                    >[/color]

                    Comment

                    • Elad

                      #11
                      Re: Single instance of an object between different processes?

                      That's more like it! :-)

                      Thanks for your help.

                      Elad

                      "Brian Delahunty" <BrianDelahunty @discussions.mi crosoft.com> wrote in
                      message news:EDE84602-7F4E-4BA7-BFC1-533DC949DB49@mi crosoft.com...[color=blue]
                      > You could use remoting or use a Singleton class that derives from
                      > MarshalByRef and then you could keep that in a named appdomain. You then
                      > just
                      > marshal the singleton from that appdomain into the one you are using and
                      > then
                      > access the underlying object.
                      >
                      >
                      > --
                      > Brian Delahunty
                      > Ireland
                      >
                      > http://briandela.com/blog
                      >
                      > INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup I
                      > started in the southeast of Ireland.
                      >
                      >
                      > "Elad" wrote:
                      >[color=green]
                      >> Hi all, thanks for your replies.
                      >>
                      >> I may have done a poor job of explaining myself.
                      >>
                      >> I wish to use a single instance of an object across different AppDomains.
                      >> I
                      >> do not need to verify whether an EXE application already has an instance
                      >> running. The singleton pattern does not apply for multiple AppDomains,
                      >> since it is an in-process pattern.
                      >>
                      >> I believe my only choices are Remoting and WebServices. Am I wrong?
                      >>
                      >> Thanks again.
                      >>
                      >>
                      >> "Vadym Stetsyak" <vadym_s@ukr.ne t> wrote in message
                      >> news:OLP3qcYoFH A.1872@TK2MSFTN GP10.phx.gbl...[color=darkred]
                      >> > You can also use remoting here, and use the object in the singletone
                      >> > instantiation pattern
                      >> >
                      >> > --
                      >> > Vadym Stetsyak aka Vadmyst
                      >> >
                      >> > "Brian Delahunty" <BrianDelahunty @discussions.mi crosoft.com> wrote in
                      >> > message news:6FF63B5C-8C82-444F-9C89-9678ADB0224B@mi crosoft.com...
                      >> >> Read up on Mutex's or check out this article on the CodeProject which
                      >> >> explains how to do it:
                      >> >>
                      >> >> http://www.codeproject.com/csharp/singleinstance.asp
                      >> >>
                      >> >> Hope this helps.
                      >> >>
                      >> >> --
                      >> >> Brian Delahunty
                      >> >> Ireland
                      >> >>
                      >> >> http://briandela.com/blog
                      >> >>
                      >> >> INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup
                      >> >> I
                      >> >> started in the southeast of Ireland.
                      >> >>
                      >> >>
                      >> >> "Elad" wrote:
                      >> >>
                      >> >> > Hi,
                      >> >> >
                      >> >> > I have an application that is made up of several executables. I
                      >> >> > need
                      >> > all
                      >> >> > these executables to use the same instance of an object.
                      >> >> >
                      >> >> > What is the best, most efficient way to approach this?
                      >> >> >
                      >> >> > Thanks a lot!
                      >> >> >
                      >> >> >
                      >> >> >
                      >> >
                      >> >[/color]
                      >>
                      >>
                      >>[/color][/color]


                      Comment

                      • Brian Delahunty

                        #12
                        Re: Single instance of an object between different processes?

                        Let me know if it works for you and sorry for the confusion earlier! I'm on a
                        go-slow today :-)

                        --
                        Brian Delahunty
                        Ireland



                        INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup I
                        started in the southeast of Ireland.


                        "Elad" wrote:
                        [color=blue]
                        > That's more like it! :-)
                        >
                        > Thanks for your help.
                        >
                        > Elad
                        >
                        > "Brian Delahunty" <BrianDelahunty @discussions.mi crosoft.com> wrote in
                        > message news:EDE84602-7F4E-4BA7-BFC1-533DC949DB49@mi crosoft.com...[color=green]
                        > > You could use remoting or use a Singleton class that derives from
                        > > MarshalByRef and then you could keep that in a named appdomain. You then
                        > > just
                        > > marshal the singleton from that appdomain into the one you are using and
                        > > then
                        > > access the underlying object.
                        > >
                        > >
                        > > --
                        > > Brian Delahunty
                        > > Ireland
                        > >
                        > > http://briandela.com/blog
                        > >
                        > > INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup I
                        > > started in the southeast of Ireland.
                        > >
                        > >
                        > > "Elad" wrote:
                        > >[color=darkred]
                        > >> Hi all, thanks for your replies.
                        > >>
                        > >> I may have done a poor job of explaining myself.
                        > >>
                        > >> I wish to use a single instance of an object across different AppDomains.
                        > >> I
                        > >> do not need to verify whether an EXE application already has an instance
                        > >> running. The singleton pattern does not apply for multiple AppDomains,
                        > >> since it is an in-process pattern.
                        > >>
                        > >> I believe my only choices are Remoting and WebServices. Am I wrong?
                        > >>
                        > >> Thanks again.
                        > >>
                        > >>
                        > >> "Vadym Stetsyak" <vadym_s@ukr.ne t> wrote in message
                        > >> news:OLP3qcYoFH A.1872@TK2MSFTN GP10.phx.gbl...
                        > >> > You can also use remoting here, and use the object in the singletone
                        > >> > instantiation pattern
                        > >> >
                        > >> > --
                        > >> > Vadym Stetsyak aka Vadmyst
                        > >> >
                        > >> > "Brian Delahunty" <BrianDelahunty @discussions.mi crosoft.com> wrote in
                        > >> > message news:6FF63B5C-8C82-444F-9C89-9678ADB0224B@mi crosoft.com...
                        > >> >> Read up on Mutex's or check out this article on the CodeProject which
                        > >> >> explains how to do it:
                        > >> >>
                        > >> >> http://www.codeproject.com/csharp/singleinstance.asp
                        > >> >>
                        > >> >> Hope this helps.
                        > >> >>
                        > >> >> --
                        > >> >> Brian Delahunty
                        > >> >> Ireland
                        > >> >>
                        > >> >> http://briandela.com/blog
                        > >> >>
                        > >> >> INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup
                        > >> >> I
                        > >> >> started in the southeast of Ireland.
                        > >> >>
                        > >> >>
                        > >> >> "Elad" wrote:
                        > >> >>
                        > >> >> > Hi,
                        > >> >> >
                        > >> >> > I have an application that is made up of several executables. I
                        > >> >> > need
                        > >> > all
                        > >> >> > these executables to use the same instance of an object.
                        > >> >> >
                        > >> >> > What is the best, most efficient way to approach this?
                        > >> >> >
                        > >> >> > Thanks a lot!
                        > >> >> >
                        > >> >> >
                        > >> >> >
                        > >> >
                        > >> >
                        > >>
                        > >>
                        > >>[/color][/color]
                        >
                        >
                        >[/color]

                        Comment

                        • Elad

                          #13
                          Re: Single instance of an object between different processes?

                          Don't worry about it - I'm like that everyday! And anyway, since most of
                          the people 'round here gave me answers to different questions, it's more
                          probable that I did not clarify myself.

                          Is there a way of achieving the Singleton you mentioned without involving
                          ..Net Remoting? MSDN states that MarshalByRef is used for objects that are
                          meant to support Remoting.

                          I simple need one instance of an object to be used by several applications.
                          With COM this was simple enough.....

                          "Brian Delahunty" <BrianDelahunty @discussions.mi crosoft.com> wrote in
                          message news:DCDE99A3-A665-484C-A4AA-B54D68E5441F@mi crosoft.com...[color=blue]
                          > Let me know if it works for you and sorry for the confusion earlier! I'm
                          > on a
                          > go-slow today :-)
                          >
                          > --
                          > Brian Delahunty
                          > Ireland
                          >
                          > http://briandela.com/blog
                          >
                          > INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup I
                          > started in the southeast of Ireland.
                          >
                          >
                          > "Elad" wrote:
                          >[color=green]
                          >> That's more like it! :-)
                          >>
                          >> Thanks for your help.
                          >>
                          >> Elad
                          >>
                          >> "Brian Delahunty" <BrianDelahunty @discussions.mi crosoft.com> wrote in
                          >> message news:EDE84602-7F4E-4BA7-BFC1-533DC949DB49@mi crosoft.com...[color=darkred]
                          >> > You could use remoting or use a Singleton class that derives from
                          >> > MarshalByRef and then you could keep that in a named appdomain. You
                          >> > then
                          >> > just
                          >> > marshal the singleton from that appdomain into the one you are using
                          >> > and
                          >> > then
                          >> > access the underlying object.
                          >> >
                          >> >
                          >> > --
                          >> > Brian Delahunty
                          >> > Ireland
                          >> >
                          >> > http://briandela.com/blog
                          >> >
                          >> > INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup I
                          >> > started in the southeast of Ireland.
                          >> >
                          >> >
                          >> > "Elad" wrote:
                          >> >
                          >> >> Hi all, thanks for your replies.
                          >> >>
                          >> >> I may have done a poor job of explaining myself.
                          >> >>
                          >> >> I wish to use a single instance of an object across different
                          >> >> AppDomains.
                          >> >> I
                          >> >> do not need to verify whether an EXE application already has an
                          >> >> instance
                          >> >> running. The singleton pattern does not apply for multiple
                          >> >> AppDomains,
                          >> >> since it is an in-process pattern.
                          >> >>
                          >> >> I believe my only choices are Remoting and WebServices. Am I wrong?
                          >> >>
                          >> >> Thanks again.
                          >> >>
                          >> >>
                          >> >> "Vadym Stetsyak" <vadym_s@ukr.ne t> wrote in message
                          >> >> news:OLP3qcYoFH A.1872@TK2MSFTN GP10.phx.gbl...
                          >> >> > You can also use remoting here, and use the object in the singletone
                          >> >> > instantiation pattern
                          >> >> >
                          >> >> > --
                          >> >> > Vadym Stetsyak aka Vadmyst
                          >> >> >
                          >> >> > "Brian Delahunty" <BrianDelahunty @discussions.mi crosoft.com> wrote
                          >> >> > in
                          >> >> > message news:6FF63B5C-8C82-444F-9C89-9678ADB0224B@mi crosoft.com...
                          >> >> >> Read up on Mutex's or check out this article on the CodeProject
                          >> >> >> which
                          >> >> >> explains how to do it:
                          >> >> >>
                          >> >> >> http://www.codeproject.com/csharp/singleinstance.asp
                          >> >> >>
                          >> >> >> Hope this helps.
                          >> >> >>
                          >> >> >> --
                          >> >> >> Brian Delahunty
                          >> >> >> Ireland
                          >> >> >>
                          >> >> >> http://briandela.com/blog
                          >> >> >>
                          >> >> >> INDA SouthEast - http://southeast.developers.ie/ - The .NET
                          >> >> >> usergroup
                          >> >> >> I
                          >> >> >> started in the southeast of Ireland.
                          >> >> >>
                          >> >> >>
                          >> >> >> "Elad" wrote:
                          >> >> >>
                          >> >> >> > Hi,
                          >> >> >> >
                          >> >> >> > I have an application that is made up of several executables. I
                          >> >> >> > need
                          >> >> > all
                          >> >> >> > these executables to use the same instance of an object.
                          >> >> >> >
                          >> >> >> > What is the best, most efficient way to approach this?
                          >> >> >> >
                          >> >> >> > Thanks a lot!
                          >> >> >> >
                          >> >> >> >
                          >> >> >> >
                          >> >> >
                          >> >> >
                          >> >>
                          >> >>
                          >> >>[/color]
                          >>
                          >>
                          >>[/color][/color]


                          Comment

                          • Brian Delahunty

                            #14
                            Re: Single instance of an object between different processes?

                            You don't have to use remoting. MarshalByRef just allows you to marshal
                            across app boundaries (including appdomains). You don't need to use remoting
                            at all.

                            For example:

                            // Your Singleton
                            private class ExampleSingleto nClass: System.MarshalB yRefObject
                            {
                            // Singleton implementation
                            }

                            The singleton will be created in a named appdomain... for example:


                            // Create a temporary application domain to load the singleton into
                            AppDomain singletonDomain = AppDomain.Creat eDomain("Single tonDomain");

                            ExampleSingleto nClass singleton =
                            singletonDomain .CreateInstance FromAndUnwrap(A ssembly.GetExec utingAssembly() .Location, typeof(ExampleS ingletonClass). FullName) as ExampleSingleto nClass;

                            // Do whatever you want with the singleton

                            // At the end of your app, kill the singleton domain
                            AppDomain.Unloa d(singletonDoma in);



                            Hope this helps.

                            --
                            Brian Delahunty
                            Ireland



                            INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup I
                            started in the southeast of Ireland.


                            "Elad" wrote:
                            [color=blue]
                            > Don't worry about it - I'm like that everyday! And anyway, since most of
                            > the people 'round here gave me answers to different questions, it's more
                            > probable that I did not clarify myself.
                            >
                            > Is there a way of achieving the Singleton you mentioned without involving
                            > ..Net Remoting? MSDN states that MarshalByRef is used for objects that are
                            > meant to support Remoting.
                            >
                            > I simple need one instance of an object to be used by several applications.
                            > With COM this was simple enough.....
                            >
                            > "Brian Delahunty" <BrianDelahunty @discussions.mi crosoft.com> wrote in
                            > message news:DCDE99A3-A665-484C-A4AA-B54D68E5441F@mi crosoft.com...[color=green]
                            > > Let me know if it works for you and sorry for the confusion earlier! I'm
                            > > on a
                            > > go-slow today :-)
                            > >
                            > > --
                            > > Brian Delahunty
                            > > Ireland
                            > >
                            > > http://briandela.com/blog
                            > >
                            > > INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup I
                            > > started in the southeast of Ireland.
                            > >
                            > >
                            > > "Elad" wrote:
                            > >[color=darkred]
                            > >> That's more like it! :-)
                            > >>
                            > >> Thanks for your help.
                            > >>
                            > >> Elad
                            > >>
                            > >> "Brian Delahunty" <BrianDelahunty @discussions.mi crosoft.com> wrote in
                            > >> message news:EDE84602-7F4E-4BA7-BFC1-533DC949DB49@mi crosoft.com...
                            > >> > You could use remoting or use a Singleton class that derives from
                            > >> > MarshalByRef and then you could keep that in a named appdomain. You
                            > >> > then
                            > >> > just
                            > >> > marshal the singleton from that appdomain into the one you are using
                            > >> > and
                            > >> > then
                            > >> > access the underlying object.
                            > >> >
                            > >> >
                            > >> > --
                            > >> > Brian Delahunty
                            > >> > Ireland
                            > >> >
                            > >> > http://briandela.com/blog
                            > >> >
                            > >> > INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup I
                            > >> > started in the southeast of Ireland.
                            > >> >
                            > >> >
                            > >> > "Elad" wrote:
                            > >> >
                            > >> >> Hi all, thanks for your replies.
                            > >> >>
                            > >> >> I may have done a poor job of explaining myself.
                            > >> >>
                            > >> >> I wish to use a single instance of an object across different
                            > >> >> AppDomains.
                            > >> >> I
                            > >> >> do not need to verify whether an EXE application already has an
                            > >> >> instance
                            > >> >> running. The singleton pattern does not apply for multiple
                            > >> >> AppDomains,
                            > >> >> since it is an in-process pattern.
                            > >> >>
                            > >> >> I believe my only choices are Remoting and WebServices. Am I wrong?
                            > >> >>
                            > >> >> Thanks again.
                            > >> >>
                            > >> >>
                            > >> >> "Vadym Stetsyak" <vadym_s@ukr.ne t> wrote in message
                            > >> >> news:OLP3qcYoFH A.1872@TK2MSFTN GP10.phx.gbl...
                            > >> >> > You can also use remoting here, and use the object in the singletone
                            > >> >> > instantiation pattern
                            > >> >> >
                            > >> >> > --
                            > >> >> > Vadym Stetsyak aka Vadmyst
                            > >> >> >
                            > >> >> > "Brian Delahunty" <BrianDelahunty @discussions.mi crosoft.com> wrote
                            > >> >> > in
                            > >> >> > message news:6FF63B5C-8C82-444F-9C89-9678ADB0224B@mi crosoft.com...
                            > >> >> >> Read up on Mutex's or check out this article on the CodeProject
                            > >> >> >> which
                            > >> >> >> explains how to do it:
                            > >> >> >>
                            > >> >> >> http://www.codeproject.com/csharp/singleinstance.asp
                            > >> >> >>
                            > >> >> >> Hope this helps.
                            > >> >> >>
                            > >> >> >> --
                            > >> >> >> Brian Delahunty
                            > >> >> >> Ireland
                            > >> >> >>
                            > >> >> >> http://briandela.com/blog
                            > >> >> >>
                            > >> >> >> INDA SouthEast - http://southeast.developers.ie/ - The .NET
                            > >> >> >> usergroup
                            > >> >> >> I
                            > >> >> >> started in the southeast of Ireland.
                            > >> >> >>
                            > >> >> >>
                            > >> >> >> "Elad" wrote:
                            > >> >> >>
                            > >> >> >> > Hi,
                            > >> >> >> >
                            > >> >> >> > I have an application that is made up of several executables. I
                            > >> >> >> > need
                            > >> >> > all
                            > >> >> >> > these executables to use the same instance of an object.
                            > >> >> >> >
                            > >> >> >> > What is the best, most efficient way to approach this?
                            > >> >> >> >
                            > >> >> >> > Thanks a lot!
                            > >> >> >> >
                            > >> >> >> >
                            > >> >> >> >
                            > >> >> >
                            > >> >> >
                            > >> >>
                            > >> >>
                            > >> >>
                            > >>
                            > >>
                            > >>[/color][/color]
                            >
                            >
                            >[/color]

                            Comment

                            • Elad

                              #15
                              Re: Single instance of an object between different processes?

                              Brian,

                              Thanks a lot for the detailed example. I'll check it out and see if it
                              works for me.

                              Thanks again.

                              Elad

                              "Brian Delahunty" <BrianDelahunty @discussions.mi crosoft.com> wrote in
                              message news:3E3C23BE-0B37-4330-9B1E-EC8E1EACD3F6@mi crosoft.com...[color=blue]
                              > You don't have to use remoting. MarshalByRef just allows you to marshal
                              > across app boundaries (including appdomains). You don't need to use
                              > remoting
                              > at all.
                              >
                              > For example:
                              >
                              > // Your Singleton
                              > private class ExampleSingleto nClass: System.MarshalB yRefObject
                              > {
                              > // Singleton implementation
                              > }
                              >
                              > The singleton will be created in a named appdomain... for example:
                              >
                              >
                              > // Create a temporary application domain to load the singleton into
                              > AppDomain singletonDomain = AppDomain.Creat eDomain("Single tonDomain");
                              >
                              > ExampleSingleto nClass singleton =
                              > singletonDomain .CreateInstance FromAndUnwrap(A ssembly.GetExec utingAssembly() .Location,
                              > typeof(ExampleS ingletonClass). FullName) as ExampleSingleto nClass;
                              >
                              > // Do whatever you want with the singleton
                              >
                              > // At the end of your app, kill the singleton domain
                              > AppDomain.Unloa d(singletonDoma in);
                              >
                              >
                              >
                              > Hope this helps.
                              >
                              > --
                              > Brian Delahunty
                              > Ireland
                              >
                              > http://briandela.com/blog
                              >
                              > INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup I
                              > started in the southeast of Ireland.
                              >
                              >
                              > "Elad" wrote:
                              >[color=green]
                              >> Don't worry about it - I'm like that everyday! And anyway, since most of
                              >> the people 'round here gave me answers to different questions, it's more
                              >> probable that I did not clarify myself.
                              >>
                              >> Is there a way of achieving the Singleton you mentioned without involving
                              >> ..Net Remoting? MSDN states that MarshalByRef is used for objects that
                              >> are
                              >> meant to support Remoting.
                              >>
                              >> I simple need one instance of an object to be used by several
                              >> applications.
                              >> With COM this was simple enough.....
                              >>
                              >> "Brian Delahunty" <BrianDelahunty @discussions.mi crosoft.com> wrote in
                              >> message news:DCDE99A3-A665-484C-A4AA-B54D68E5441F@mi crosoft.com...[color=darkred]
                              >> > Let me know if it works for you and sorry for the confusion earlier!
                              >> > I'm
                              >> > on a
                              >> > go-slow today :-)
                              >> >
                              >> > --
                              >> > Brian Delahunty
                              >> > Ireland
                              >> >
                              >> > http://briandela.com/blog
                              >> >
                              >> > INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup I
                              >> > started in the southeast of Ireland.
                              >> >
                              >> >
                              >> > "Elad" wrote:
                              >> >
                              >> >> That's more like it! :-)
                              >> >>
                              >> >> Thanks for your help.
                              >> >>
                              >> >> Elad
                              >> >>
                              >> >> "Brian Delahunty" <BrianDelahunty @discussions.mi crosoft.com> wrote in
                              >> >> message news:EDE84602-7F4E-4BA7-BFC1-533DC949DB49@mi crosoft.com...
                              >> >> > You could use remoting or use a Singleton class that derives from
                              >> >> > MarshalByRef and then you could keep that in a named appdomain. You
                              >> >> > then
                              >> >> > just
                              >> >> > marshal the singleton from that appdomain into the one you are using
                              >> >> > and
                              >> >> > then
                              >> >> > access the underlying object.
                              >> >> >
                              >> >> >
                              >> >> > --
                              >> >> > Brian Delahunty
                              >> >> > Ireland
                              >> >> >
                              >> >> > http://briandela.com/blog
                              >> >> >
                              >> >> > INDA SouthEast - http://southeast.developers.ie/ - The .NET
                              >> >> > usergroup I
                              >> >> > started in the southeast of Ireland.
                              >> >> >
                              >> >> >
                              >> >> > "Elad" wrote:
                              >> >> >
                              >> >> >> Hi all, thanks for your replies.
                              >> >> >>
                              >> >> >> I may have done a poor job of explaining myself.
                              >> >> >>
                              >> >> >> I wish to use a single instance of an object across different
                              >> >> >> AppDomains.
                              >> >> >> I
                              >> >> >> do not need to verify whether an EXE application already has an
                              >> >> >> instance
                              >> >> >> running. The singleton pattern does not apply for multiple
                              >> >> >> AppDomains,
                              >> >> >> since it is an in-process pattern.
                              >> >> >>
                              >> >> >> I believe my only choices are Remoting and WebServices. Am I
                              >> >> >> wrong?
                              >> >> >>
                              >> >> >> Thanks again.
                              >> >> >>
                              >> >> >>
                              >> >> >> "Vadym Stetsyak" <vadym_s@ukr.ne t> wrote in message
                              >> >> >> news:OLP3qcYoFH A.1872@TK2MSFTN GP10.phx.gbl...
                              >> >> >> > You can also use remoting here, and use the object in the
                              >> >> >> > singletone
                              >> >> >> > instantiation pattern
                              >> >> >> >
                              >> >> >> > --
                              >> >> >> > Vadym Stetsyak aka Vadmyst
                              >> >> >> >
                              >> >> >> > "Brian Delahunty" <BrianDelahunty @discussions.mi crosoft.com>
                              >> >> >> > wrote
                              >> >> >> > in
                              >> >> >> > message
                              >> >> >> > news:6FF63B5C-8C82-444F-9C89-9678ADB0224B@mi crosoft.com...
                              >> >> >> >> Read up on Mutex's or check out this article on the CodeProject
                              >> >> >> >> which
                              >> >> >> >> explains how to do it:
                              >> >> >> >>
                              >> >> >> >> http://www.codeproject.com/csharp/singleinstance.asp
                              >> >> >> >>
                              >> >> >> >> Hope this helps.
                              >> >> >> >>
                              >> >> >> >> --
                              >> >> >> >> Brian Delahunty
                              >> >> >> >> Ireland
                              >> >> >> >>
                              >> >> >> >> http://briandela.com/blog
                              >> >> >> >>
                              >> >> >> >> INDA SouthEast - http://southeast.developers.ie/ - The .NET
                              >> >> >> >> usergroup
                              >> >> >> >> I
                              >> >> >> >> started in the southeast of Ireland.
                              >> >> >> >>
                              >> >> >> >>
                              >> >> >> >> "Elad" wrote:
                              >> >> >> >>
                              >> >> >> >> > Hi,
                              >> >> >> >> >
                              >> >> >> >> > I have an application that is made up of several executables.
                              >> >> >> >> > I
                              >> >> >> >> > need
                              >> >> >> > all
                              >> >> >> >> > these executables to use the same instance of an object.
                              >> >> >> >> >
                              >> >> >> >> > What is the best, most efficient way to approach this?
                              >> >> >> >> >
                              >> >> >> >> > Thanks a lot!
                              >> >> >> >> >
                              >> >> >> >> >
                              >> >> >> >> >
                              >> >> >> >
                              >> >> >> >
                              >> >> >>
                              >> >> >>
                              >> >> >>
                              >> >>
                              >> >>
                              >> >>[/color]
                              >>
                              >>
                              >>[/color][/color]


                              Comment

                              Working...