QuickOPC User's Guide and Reference
UnsubscribeItem Method (IEasyDAClientExtension)
Example 



OpcLabs.EasyOpcClassic Assembly > OpcLabs.EasyOpc.DataAccess Namespace > IEasyDAClientExtension Class : UnsubscribeItem Method
The client object that will perform the operation.
Item subscription handle as returned by the SubscribeItem method

Unsubscribe from changes of a particular OPC item.

Unsubscribe from OPC item, specifying its handle.

Syntax
'Declaration
 
<ExtensionAttribute()>
Public Shared Sub UnsubscribeItem( _
   ByVal client As IEasyDAClient, _
   ByVal handle As Integer _
) 
'Usage
 
Dim client As IEasyDAClient
Dim handle As Integer
 
IEasyDAClientExtension.UnsubscribeItem(client, handle)
[Extension()]
public static void UnsubscribeItem( 
   IEasyDAClient client,
   int handle
)
[Extension()]
public:
static void UnsubscribeItem( 
   IEasyDAClient^ client,
   int handle
) 

Parameters

client
The client object that will perform the operation.
handle
Item subscription handle as returned by the SubscribeItem method
Exceptions
ExceptionDescription
A null reference (Nothing in Visual Basic) is passed to a method that does not accept it as a valid argument.
One of the arguments provided to a method is not valid.
Remarks

It is more efficient to unsubscribe from multiple items using UnsubscribeMultipleItems method.

The item subscription handle becomes invalid after this method is called.

Example
// This example shows how subscribe to changes of multiple items, and unsubscribe from one of them.

using System;
using System.Threading;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.DataAccess.OperationModel;

namespace DocExamples.DataAccess._EasyDAClient
{
    class UnsubscribeItem
    {
        public static void Main1()
        {
            // Instantiate the client object.
            using (var client = new EasyDAClient())
            {
                client.ItemChanged += client_ItemChanged;

                int[] handleArray = client.SubscribeMultipleItems(
                    new[] {
                            new DAItemGroupArguments("", "OPCLabs.KitServer.2", "Simulation.Random", 1000, null), 
                            new DAItemGroupArguments("", "OPCLabs.KitServer.2", "Trends.Ramp (1 min)", 1000, null), 
                            new DAItemGroupArguments("", "OPCLabs.KitServer.2", "Trends.Sine (1 min)", 1000, null),  
                            new DAItemGroupArguments("", "OPCLabs.KitServer.2", "Simulation.Register_I4", 1000, null)
                        });

                Console.WriteLine("Processing item changed events for 30 seconds...");
                Thread.Sleep(30 * 1000);

                Console.WriteLine("Unsubscribing from the first item...");
                client.UnsubscribeItem(handleArray[0]);

                Console.WriteLine();

                Console.WriteLine("Processing item changed events for 30 seconds...");
                Thread.Sleep(30 * 1000);
            }
        }

        // Item changed event handler
        static void client_ItemChanged(object sender, EasyDAItemChangedEventArgs e)
        {
            if (e.Succeeded)
                Console.WriteLine("{0}: {1}", e.Arguments.ItemDescriptor.ItemId, e.Vtq);
            else
                Console.WriteLine("{0} *** Failure: {1}", e.Arguments.ItemDescriptor.ItemId, e.ErrorMessageBrief);
        }
    }
}
' This example shows how subscribe to changes of multiple items, and unsubscribe from one of them.

Imports System.Threading
Imports OpcLabs.EasyOpc.DataAccess
Imports OpcLabs.EasyOpc.DataAccess.OperationModel

Namespace DocExamples.DataAccess._EasyDAClient
    Partial Friend Class UnsubscribeItem
        Shared Sub Main1()
            Using client = New EasyDAClient()
                AddHandler client.ItemChanged, AddressOf client_ItemChanged

                Dim handleArray = client.SubscribeMultipleItems(
                        New DAItemGroupArguments() _
                        { _
                            New DAItemGroupArguments("", "OPCLabs.KitServer.2", "Simulation.Random", 1000, Nothing),
                            New DAItemGroupArguments("", "OPCLabs.KitServer.2", "Trends.Ramp (1 min)", 1000, Nothing),
                            New DAItemGroupArguments("", "OPCLabs.KitServer.2", "Trends.Sine (1 min)", 1000, Nothing),
                            New DAItemGroupArguments("", "OPCLabs.KitServer.2", "Simulation.Register_I4", 1000, Nothing)
                        })

                Console.WriteLine("Processing item changed events for 30 seconds...")
                Thread.Sleep(30 * 1000)

                Console.WriteLine("Unsubscribing from the first item...")
                client.UnsubscribeItem(handleArray(0))

                Console.WriteLine()

                Console.WriteLine("Processing item changed events for 30 seconds...")
                Thread.Sleep(30 * 1000)
            End Using
        End Sub

        ' Item changed event handler
        Private Shared Sub client_ItemChanged(sender As Object, e As EasyDAItemChangedEventArgs)
            If e.Succeeded Then
                Console.WriteLine("{0}: {1}", e.Arguments.ItemDescriptor.ItemId, e.Vtq)
            Else
                Console.WriteLine("{0} *** Failure: {1}", e.Arguments.ItemDescriptor.ItemId, e.ErrorMessageBrief)
            End If
        End Sub
    End Class
End Namespace
Requirements

Target Platforms: .NET Framework: Windows 10 (selected versions), Windows 11 (selected versions), Windows Server 2012, Windows Server 2016; .NET Core, .NET 5, .NET 6: Linux, macOS, Microsoft Windows

See Also

Reference

IEasyDAClientExtension Class
IEasyDAClientExtension Members