/// <summary>
        /// Cancels a subscription and releases all resources allocated for it.
        /// </summary>
        /// <param name="subscription">The subscription to cancel.</param>
        public void CancelSubscription(ITsCDaSubscription subscription)
        {
            if (subscription == null)
            {
                throw new ArgumentNullException(nameof(subscription));
            }

            lock (this)
            {
                if (server_ == null)
                {
                    throw new NotConnectedException();
                }
                string methodName = "IOPCServer.RemoveGroup";

                // validate argument.
                if (!typeof(Subscription).IsInstanceOfType(subscription))
                {
                    throw new ArgumentException("Incorrect object type.", nameof(subscription));
                }

                // get the subscription state.
                TsCDaSubscriptionState state = subscription.GetState();

                if (!subscriptions_.ContainsKey(state.ServerHandle))
                {
                    throw new ArgumentException("Handle not found.", nameof(subscription));
                }

                subscriptions_.Remove(state.ServerHandle);

                // release all subscription resources.
                subscription.Dispose();

                // invoke COM method.
                try
                {
                    IOPCServer server = BeginComCall <IOPCServer>(methodName, true);
                    server.RemoveGroup((int)state.ServerHandle, 0);

                    if (DCOMCallWatchdog.IsCancelled)
                    {
                        throw new Exception($"{methodName} call was cancelled due to response timeout");
                    }
                }
                catch (Exception e)
                {
                    ComCallError(methodName, e);
                    throw Utilities.Interop.CreateException(methodName, e);
                }
                finally
                {
                    EndComCall(methodName);
                }
            }
        }
 /// <summary>
 /// Returns the current subscription state.
 /// </summary>
 public TsCDaSubscriptionState GetState()
 {
     subscriptionState_ = Subscription.GetState();
     return(subscriptionState_);
 }
 /// <summary>
 /// Returns the current subscription state.
 /// </summary>
 public TsCDaSubscriptionState GetState()
 {
     _state = _subscription.GetState();
     return(_state);
 }