AdvancedHMI Software

General Category => Support Questions => Topic started by: phuz on May 10, 2020, 11:32:16 AM

Title: Unsubscribing from a subscription on form close
Post by: phuz on May 10, 2020, 11:32:16 AM
I couldn't find a relevant thread on this, so if it does exist, my apologies.

I understand that unsubscribing on close is a form of good housekeeping, but is it necessary?  If so, must you loop through each unique ID or is there a method to just dispose of all active subscriptions?

I mean, sure it's very simple...just wondering how necessary it is.

Code: [Select]
        While subscriptionID > 0
            mainplc.UnSubscribe(subscriptionID)
            subscriptionID = subscriptionID - 1
        End While
Title: Re: Unsubscribing from a subscription on form close
Post by: Archie on May 10, 2020, 11:50:10 AM
If a form is closed with a driver instance on it, all of the subscriptions are terminated automatically. This is because subscriptions live in the driver instance and not in the backend DLL. So closing a form disposes the driver instance, which in turn deletes all subscriptions
Title: Re: Unsubscribing from a subscription on form close
Post by: phuz on May 11, 2020, 01:34:29 PM
I assume the same is true if driver is initialized in a service application instead of a form?
Title: Re: Unsubscribing from a subscription on form close
Post by: Archie on May 11, 2020, 01:36:59 PM
If you are doing all code, it is up to you to properly handle disposing of driver instances. Otherwise the subscription threads will continue to run.
Title: Re: Unsubscribing from a subscription on form close
Post by: phuz on May 12, 2020, 06:26:40 AM
Would it be sufficient to say "EthernetCLXDriver.DisableSubscriptions = True" on form close and call it a day?
Title: Re: Unsubscribing from a subscription on form close
Post by: Archie on May 12, 2020, 07:16:38 AM
DisableSubcriptions only pauses the update process. It does not shut down the subscriptions threads
Title: Re: Unsubscribing from a subscription on form close
Post by: phuz on May 14, 2020, 12:40:00 PM
Is there a way to get a list of all active subscriptions?
Title: Re: Unsubscribing from a subscription on form close
Post by: Archie on May 17, 2020, 08:55:54 AM
I don't think there is a way to expose the list of active subscriptions. It is really up to you to keep a list of the subscription IDs.

If you want to unsubscribe from them all, a hack you can use is to create a new subscription to get the latest ID. The use a loop from 0 to the latest ID to call Unsubscribe on each ID