Announcement

Collapse
No announcement yet.

how to disconnect from the hs4.exe gracefully

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    how to disconnect from the hs4.exe gracefully

    alex0603 , dcorsus guys i need professional help with this one.


    After my plugin shuts down, and the command window goes away, there is still a connection to HS4. see process explorer results below.

    In my shutdownio, i set all my primary object to Nothing

    My main.vb has the following as the last statement

    _plugin = Nothing

    I need to figure how to break this connection

    Any ideas?

    Click image for larger version

Name:	open handle.png
Views:	201
Size:	9.8 KB
ID:	1545179
    Mark

    HS3 Pro 4.2.19.5
    Hardware: Insteon Serial PLM | AD2USB for Vista Alarm | HAI Omnistat2 | 1-Wire HA7E | RFXrec433 | Dahua Cameras | LiftMaster Internet Gateway | Tuya Smart Plugs
    Plugins: Insteon (mine) | Vista Alarm (mine) | Omnistat 3 | Ultra1Wire3 | RFXCOM | HS MyQ | BLRadar | BLDenon | Tuya | Jon00 Charting | Jon00 Links
    Platform: Windows Server 2022 Standard, i5-12600K/3.7GHz/10 core, 16GB RAM, 500GB SSD

    #2
    In HS4 the shutdown method is OnShutdown.

    What I do in this call from HS4 is call each of my classes shutdown method. Set all my timers to nothing after stopping them. Close all my files, ports and sockets. Release all my queue and thread semaphores. Clear all Dictionaries that are holding objects. In the past I aborted any thread that I opened, but now I use thread pool so no longer necessary. I make no effort to set the plugin to nothing.

    I have not looked at Process Explorer, but Task Manager does not reflect my plugin process after shutdown.

    I have plugin and HS stop/start/restart capability supported in mcsMQTT and I have no issue with being blocked because of a resource being taken.

    My main is

    Code:
    sub Main(args As String())
    plugin.Connect(args)
    Console.WriteLine("Exiting Main")
    End Sub

    Comment


      #3
      Same here, in OnShutDown, the PI stops all timers, speakerclients, close ports, return weblinks, dispose objects etc.

      Comment


        #4
        my plugin is not getting a call to OnShutdown when i disable the plugin from the Plugin/Manage page. Instead the old ShutdownIO is called

        edit: change to

        Protected Overrides Sub onShutdown()

        and now its being called
        Mark

        HS3 Pro 4.2.19.5
        Hardware: Insteon Serial PLM | AD2USB for Vista Alarm | HAI Omnistat2 | 1-Wire HA7E | RFXrec433 | Dahua Cameras | LiftMaster Internet Gateway | Tuya Smart Plugs
        Plugins: Insteon (mine) | Vista Alarm (mine) | Omnistat 3 | Ultra1Wire3 | RFXCOM | HS MyQ | BLRadar | BLDenon | Tuya | Jon00 Charting | Jon00 Links
        Platform: Windows Server 2022 Standard, i5-12600K/3.7GHz/10 core, 16GB RAM, 500GB SSD

        Comment


          #5
          Originally posted by mnsandler View Post
          my plugin is not getting a call to OnShutdown when i disable the plugin from the Plugin/Manage page. Instead the old ShutdownIO is called

          edit: change to

          Protected Overrides Sub onShutdown()

          and now its being called

          Comment


            #6
            for the record, i think the change that finally worked was setting my Threads to nothing after they stopped. I have logic to exit the thread when the plugin shuts down but i guess that wasn't good enough
            Mark

            HS3 Pro 4.2.19.5
            Hardware: Insteon Serial PLM | AD2USB for Vista Alarm | HAI Omnistat2 | 1-Wire HA7E | RFXrec433 | Dahua Cameras | LiftMaster Internet Gateway | Tuya Smart Plugs
            Plugins: Insteon (mine) | Vista Alarm (mine) | Omnistat 3 | Ultra1Wire3 | RFXCOM | HS MyQ | BLRadar | BLDenon | Tuya | Jon00 Charting | Jon00 Links
            Platform: Windows Server 2022 Standard, i5-12600K/3.7GHz/10 core, 16GB RAM, 500GB SSD

            Comment


              #7
              I found that using "ThreadPool.QueueWorkItem" to be more efficient than "New Thread" and does not require any additional management to assure resources are not tied up. For example, the oResendThread created with the first method requires the plugin to manage the resource. This object is not created in the second method. Any cleanup activity that may be needed is handled implicitly by .NET. as it manages the ThreadPool.

              Code:
              From
              
              oResendThread = New System.Threading.Thread(AddressOf ResendThread)
              oResendThread.Start()
              
              
              To
              
              System.Threading.ThreadPool.QueueUserWorkItem(AddressOf ResendThread)

              Comment


                #8
                thanks Michael

                I started using the threadpool for newer code, just never went back and converted the original ones
                Mark

                HS3 Pro 4.2.19.5
                Hardware: Insteon Serial PLM | AD2USB for Vista Alarm | HAI Omnistat2 | 1-Wire HA7E | RFXrec433 | Dahua Cameras | LiftMaster Internet Gateway | Tuya Smart Plugs
                Plugins: Insteon (mine) | Vista Alarm (mine) | Omnistat 3 | Ultra1Wire3 | RFXCOM | HS MyQ | BLRadar | BLDenon | Tuya | Jon00 Charting | Jon00 Links
                Platform: Windows Server 2022 Standard, i5-12600K/3.7GHz/10 core, 16GB RAM, 500GB SSD

                Comment


                  #9
                  I'm using Task.Factory.StartNew

                  Comment

                  Working...
                  X