how to share a static variable between 2 different process

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?UmljY2FyZG8=?=

    how to share a static variable between 2 different process

    Hi everybody,
    I have a c# dll and I want to call the class library from several
    applications.
    I need some variables to be static in the memory space, not locally to each
    process.
    Thus, if application A modifies the variable X of a class contained in the
    dll, application B should be able to see the changed value.
    Does anybody has any idea of how to obtain this?

    Thanks in advance.
    Riccardo
  • =?Utf-8?B?Q2lhcmFuIE8nJ0Rvbm5lbGw=?=

    #2
    RE: how to share a static variable between 2 different process

    This is not possible with normall coding in .NET. You would need to setup
    interprocess communication in a client server type way.
    Remoting or WCF would be the best mechanisms for establishing but you would
    need to work out which process should hold the master copy and then create a
    service in it for the other processes to access it. You could potentially
    propogate changes around with events/callbacks over the communication channel.

    The other option is to hold the values in a database, or the registry or
    some other centralised storage mechanism.
    If you give a bit more information on the requirement we might be able to
    help you choose the best way to do it.

    HTH

    --
    Ciaran O''Donnell
    try{ Life(); } catch (TooDifficultException) { throw Toys(); }



    "Riccardo" wrote:
    Hi everybody,
    I have a c# dll and I want to call the class library from several
    applications.
    I need some variables to be static in the memory space, not locally to each
    process.
    Thus, if application A modifies the variable X of a class contained in the
    dll, application B should be able to see the changed value.
    Does anybody has any idea of how to obtain this?
    >
    Thanks in advance.
    Riccardo

    Comment

    • =?Utf-8?B?UmljY2FyZG8=?=

      #3
      RE: how to share a static variable between 2 different process

      This is not a good news for me :-)
      I'll try to explain better: my dll has been exposed as a COM object thanks
      to interop. All the clients could call some methods like ListAvailableSe ats,
      ReserveSeat, PaySeat, etc. The dll has a full control on the access db where
      available seats are stored. The db just has 2 fields: Id, Description. I
      cannot change its structure.
      The multiple COM clients could be located on different machines, require the
      list of the available seats, reserve one of them and pay the reserved one. Of
      course one client could pay only seats who reserved itself.
      The only operation that the dll could do on the db (except reading it) is to
      remove the appropriate record whenever the seat is paid.
      What I would like to do is keeping trace (possibly only in memory, not on
      disk) of the reservations and the related process who made the reservations.

      Thanks.
      Riccardo Mingozzi

      "Ciaran O''Donnell" wrote:
      This is not possible with normall coding in .NET. You would need to setup
      interprocess communication in a client server type way.
      Remoting or WCF would be the best mechanisms for establishing but you would
      need to work out which process should hold the master copy and then create a
      service in it for the other processes to access it. You could potentially
      propogate changes around with events/callbacks over the communication channel.
      >
      The other option is to hold the values in a database, or the registry or
      some other centralised storage mechanism.
      If you give a bit more information on the requirement we might be able to
      help you choose the best way to do it.
      >
      HTH
      >
      --
      Ciaran O''Donnell
      try{ Life(); } catch (TooDifficultException) { throw Toys(); }

      >
      >
      "Riccardo" wrote:
      >
      Hi everybody,
      I have a c# dll and I want to call the class library from several
      applications.
      I need some variables to be static in the memory space, not locally to each
      process.
      Thus, if application A modifies the variable X of a class contained in the
      dll, application B should be able to see the changed value.
      Does anybody has any idea of how to obtain this?

      Thanks in advance.
      Riccardo

      Comment

      • Alberto Poblacion

        #4
        Re: how to share a static variable between 2 different process

        "Riccardo" <Riccardo@discu ssions.microsof t.comwrote in message
        news:D430BE73-37E6-4F4C-B61A-0DBDC84ABA1D@mi crosoft.com...
        This is not a good news for me :-)
        I'll try to explain better: my dll has been exposed as a COM object thanks
        to interop. All the clients could call some methods like
        ListAvailableSe ats,
        ReserveSeat, PaySeat, etc. The dll has a full control on the access db
        where
        available seats are stored. The db just has 2 fields: Id, Description. I
        cannot change its structure.
        The multiple COM clients could be located on different machines, require
        the
        list of the available seats, reserve one of them and pay the reserved one.
        Of
        course one client could pay only seats who reserved itself.
        The only operation that the dll could do on the db (except reading it) is
        to
        remove the appropriate record whenever the seat is paid.
        What I would like to do is keeping trace (possibly only in memory, not on
        disk) of the reservations and the related process who made the
        reservations.
        Go beyond COM: use COM+.
        Make the class inside your DLL inherit from
        System.Enterpri seServices.Serv icedComponent. Then register the DLL in
        ComponentServic es in a server. If you need to call it from various client
        PCs, you can generate a proxy from the Component Services administration
        tool, and then install the proxy on the clients. This is not needed if the
        programs that call the dll are running on the same computer.
        You can configure COM+ to run the DLL in server mode (versus library
        mode). You can then use static variables, or use the Shared Property Manager
        in COM+, to share your values in memory between all callers.

        The complete process is a little more complex than hinted above.
        Microsoft official course number 2557 describes how to program COM+ using
        ..Net.

        Comment

        • =?Utf-8?B?Q2lhcmFuIE8nJ0Rvbm5lbGw=?=

          #5
          RE: how to share a static variable between 2 different process

          Ok, so thats a little different. If you are using COM then you can load the
          dll into Component Services in Windows as a COM+ server. There are various
          tutorials on the web that will talk you through registering the server and
          generating a type library (tlb) file to add as a reference to your client
          code.
          Architecturally it would be nicer to move away from COM and setup a WCF
          service to host the server and have that access a SQL Server (SQLEXPRESS is
          free) database but if you really cant change that then dont worry about it.

          Here is a page which gives a walkthrough of building a COM+ server
          application which is implemented in .NET

          Hope this helps

          --
          Ciaran O''Donnell
          try{ Life(); } catch (TooDifficultException) { throw Toys(); }



          "Riccardo" wrote:
          This is not a good news for me :-)
          I'll try to explain better: my dll has been exposed as a COM object thanks
          to interop. All the clients could call some methods like ListAvailableSe ats,
          ReserveSeat, PaySeat, etc. The dll has a full control on the access db where
          available seats are stored. The db just has 2 fields: Id, Description. I
          cannot change its structure.
          The multiple COM clients could be located on different machines, require the
          list of the available seats, reserve one of them and pay the reserved one. Of
          course one client could pay only seats who reserved itself.
          The only operation that the dll could do on the db (except reading it) is to
          remove the appropriate record whenever the seat is paid.
          What I would like to do is keeping trace (possibly only in memory, not on
          disk) of the reservations and the related process who made the reservations.
          >
          Thanks.
          Riccardo Mingozzi
          >
          "Ciaran O''Donnell" wrote:
          >
          This is not possible with normall coding in .NET. You would need to setup
          interprocess communication in a client server type way.
          Remoting or WCF would be the best mechanisms for establishing but you would
          need to work out which process should hold the master copy and then create a
          service in it for the other processes to access it. You could potentially
          propogate changes around with events/callbacks over the communication channel.

          The other option is to hold the values in a database, or the registry or
          some other centralised storage mechanism.
          If you give a bit more information on the requirement we might be able to
          help you choose the best way to do it.

          HTH

          --
          Ciaran O''Donnell
          try{ Life(); } catch (TooDifficultException) { throw Toys(); }



          "Riccardo" wrote:
          Hi everybody,
          I have a c# dll and I want to call the class library from several
          applications.
          I need some variables to be static in the memory space, not locally to each
          process.
          Thus, if application A modifies the variable X of a class contained in the
          dll, application B should be able to see the changed value.
          Does anybody has any idea of how to obtain this?
          >
          Thanks in advance.
          Riccardo

          Comment

          • =?Utf-8?B?UmljY2FyZG8=?=

            #6
            RE: how to share a static variable between 2 different process

            Sorry, maybe you forgot the link to the page.
            Thanks.

            "Ciaran O''Donnell" wrote:
            Ok, so thats a little different. If you are using COM then you can load the
            dll into Component Services in Windows as a COM+ server. There are various
            tutorials on the web that will talk you through registering the server and
            generating a type library (tlb) file to add as a reference to your client
            code.
            Architecturally it would be nicer to move away from COM and setup a WCF
            service to host the server and have that access a SQL Server (SQLEXPRESS is
            free) database but if you really cant change that then dont worry about it.
            >
            Here is a page which gives a walkthrough of building a COM+ server
            application which is implemented in .NET
            >
            Hope this helps
            >
            --
            Ciaran O''Donnell
            try{ Life(); } catch (TooDifficultException) { throw Toys(); }

            >
            >
            "Riccardo" wrote:
            >
            This is not a good news for me :-)
            I'll try to explain better: my dll has been exposed as a COM object thanks
            to interop. All the clients could call some methods like ListAvailableSe ats,
            ReserveSeat, PaySeat, etc. The dll has a full control on the access db where
            available seats are stored. The db just has 2 fields: Id, Description. I
            cannot change its structure.
            The multiple COM clients could be located on different machines, require the
            list of the available seats, reserve one of them and pay the reserved one. Of
            course one client could pay only seats who reserved itself.
            The only operation that the dll could do on the db (except reading it) is to
            remove the appropriate record whenever the seat is paid.
            What I would like to do is keeping trace (possibly only in memory, not on
            disk) of the reservations and the related process who made the reservations.

            Thanks.
            Riccardo Mingozzi

            "Ciaran O''Donnell" wrote:
            This is not possible with normall coding in .NET. You would need to setup
            interprocess communication in a client server type way.
            Remoting or WCF would be the best mechanisms for establishing but you would
            need to work out which process should hold the master copy and then create a
            service in it for the other processes to access it. You could potentially
            propogate changes around with events/callbacks over the communication channel.
            >
            The other option is to hold the values in a database, or the registry or
            some other centralised storage mechanism.
            If you give a bit more information on the requirement we might be able to
            help you choose the best way to do it.
            >
            HTH
            >
            --
            Ciaran O''Donnell
            try{ Life(); } catch (TooDifficultException) { throw Toys(); }

            >
            >
            "Riccardo" wrote:
            >
            Hi everybody,
            I have a c# dll and I want to call the class library from several
            applications.
            I need some variables to be static in the memory space, not locally to each
            process.
            Thus, if application A modifies the variable X of a class contained in the
            dll, application B should be able to see the changed value.
            Does anybody has any idea of how to obtain this?

            Thanks in advance.
            Riccardo

            Comment

            • =?Utf-8?B?Q2lhcmFuIE8nJ0Rvbm5lbGw=?=

              #7
              RE: how to share a static variable between 2 different process

              Yes, it appears I did. Sorry about that.
              Here it is:


              It might not be exactly what your after but it look like a good starter for 10


              --
              Ciaran O''Donnell
              try{ Life(); } catch (TooDifficultException) { throw Toys(); }



              "Riccardo" wrote:
              Sorry, maybe you forgot the link to the page.
              Thanks.
              >
              "Ciaran O''Donnell" wrote:
              >
              Ok, so thats a little different. If you are using COM then you can load the
              dll into Component Services in Windows as a COM+ server. There are various
              tutorials on the web that will talk you through registering the server and
              generating a type library (tlb) file to add as a reference to your client
              code.
              Architecturally it would be nicer to move away from COM and setup a WCF
              service to host the server and have that access a SQL Server (SQLEXPRESS is
              free) database but if you really cant change that then dont worry about it.

              Here is a page which gives a walkthrough of building a COM+ server
              application which is implemented in .NET

              Hope this helps

              --
              Ciaran O''Donnell
              try{ Life(); } catch (TooDifficultException) { throw Toys(); }



              "Riccardo" wrote:
              This is not a good news for me :-)
              I'll try to explain better: my dll has been exposed as a COM object thanks
              to interop. All the clients could call some methods like ListAvailableSe ats,
              ReserveSeat, PaySeat, etc. The dll has a full control on the access db where
              available seats are stored. The db just has 2 fields: Id, Description. I
              cannot change its structure.
              The multiple COM clients could be located on different machines, require the
              list of the available seats, reserve one of them and pay the reserved one. Of
              course one client could pay only seats who reserved itself.
              The only operation that the dll could do on the db (except reading it) is to
              remove the appropriate record whenever the seat is paid.
              What I would like to do is keeping trace (possibly only in memory, not on
              disk) of the reservations and the related process who made the reservations.
              >
              Thanks.
              Riccardo Mingozzi
              >
              "Ciaran O''Donnell" wrote:
              >
              This is not possible with normall coding in .NET. You would need to setup
              interprocess communication in a client server type way.
              Remoting or WCF would be the best mechanisms for establishing but you would
              need to work out which process should hold the master copy and then create a
              service in it for the other processes to access it. You could potentially
              propogate changes around with events/callbacks over the communication channel.

              The other option is to hold the values in a database, or the registry or
              some other centralised storage mechanism.
              If you give a bit more information on the requirement we might be able to
              help you choose the best way to do it.

              HTH

              --
              Ciaran O''Donnell
              try{ Life(); } catch (TooDifficultException) { throw Toys(); }



              "Riccardo" wrote:

              Hi everybody,
              I have a c# dll and I want to call the class library from several
              applications.
              I need some variables to be static in the memory space, not locally to each
              process.
              Thus, if application A modifies the variable X of a class contained in the
              dll, application B should be able to see the changed value.
              Does anybody has any idea of how to obtain this?
              >
              Thanks in advance.
              Riccardo

              Comment

              Working...