1 Reply Latest reply on Dec 5, 2011 6:09 PM by charlie@osisoft.com

    Threading

    aspringstroh

      If a class has fields PISDK and Server that are created during the constructor of said class, can you spin out threads within the constructor that call methods that make use of the same Server class field?

       

       

       

      class Test
      {
      
          PISDK.PISDK myPISDK = new PISDK.PISDK();
          PISDK.Server myPIServer;
          
          public Test()
          {
              myPIServer = myPISDK.Servers.DefaultServer;
              SpinThreads();
          }
          ~Test()
          {
              myPIServer.Close();
          }
          private void SpinThreads()
          {
              //Create threads that use 
              PISDK.PIPoint myPIPoint = myPIServer.PIPoints[tagname];
          }
      }
      

       Is this safe?

       

       

       

       

        • Re: Threading

          Aaron,

           

          If the class is created in an STA thread and SpinThreads creates another STA or MTA thread, the STA COM calls would be marshaled back to the class's STA thread.  COM manages the safety, but the performance would suffer.

           

          Likewise if the class is created in an MTA thread, and associated STA thread would host the PISDK.  SpinThreads would marshal calls back to that associated thread.