OPC Studio User's Guide and Reference
UnsubscribeMonitoredItem Method (_EasyUAClient)
Example 



OpcLabs.EasyOpcUA Assembly > OpcLabs.EasyOpc.UA.ComTypes Namespace > _EasyUAClient Interface : UnsubscribeMonitoredItem Method
Monitored item subscription handle as returned by the subscription method
Unsubscribe from changes of a particular monitored item.

Unsubscribe from monitored item, specifying its handle.

Syntax
'Declaration
 
Sub UnsubscribeMonitoredItem( _
   ByVal handle As Integer _
) 
'Usage
 
Dim instance As _EasyUAClient
Dim handle As Integer
 
instance.UnsubscribeMonitoredItem(handle)
void UnsubscribeMonitoredItem( 
   int handle
)
void UnsubscribeMonitoredItem( 
   int handle
) 

Parameters

handle
Monitored item subscription handle as returned by the subscription method
Exceptions
ExceptionDescription

One of the arguments provided to a method is not valid.

This is a usage error, i.e. it will never occur (the exception will not be thrown) in a correctly written program. Your code should not catch this exception.

A null reference (Nothing in Visual Basic) is passed to a method that does not accept it as a valid argument.

This is a usage error, i.e. it will never occur (the exception will not be thrown) in a correctly written program. Your code should not catch this exception.

Remarks

It is more efficient to unsubscribe from multiple items using the OpcLabs.EasyOpc.UA.IEasyUAClient.UnsubscribeMultipleMonitoredItems method.

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

This member or type is for use from COM. It is not meant to be used from .NET or Python. Refer to the corresponding .NET member or type instead, if you are developing in .NET or Python.

This is an extension method (info: C#, VB.NET). In languages that have support for extensions methods (such as C# and VB.NET), you can use the extension method as if it were a regular method on the object that is its first parameter. In other languages (such as with Python.NET), you will call the extension as a static method, and pass it the object on which it acts as its first parameter.

Example

COM

Rem This example shows how unsubscribe from changes of a single monitored item.
Rem
Rem Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
Rem OPC client and subscriber examples in VBScript on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBScript .
Rem Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
Rem a commercial license in order to use Online Forums, and we reply to every post.

Option Explicit

' Instantiate the client object and hook events
Dim Client: Set Client= CreateObject("OpcLabs.EasyOpc.UA.EasyUAClient")
WScript.ConnectObject Client, "Client_"

WScript.Echo "Subscribing..."
Dim handle: handle = Client.SubscribeDataChange("opc.tcp://opcua.demo-this.com:51210/UA/SampleServer", "nsu=http://test.org/UA/Data/ ;i=10853", 1000)

WScript.Echo "Processing monitored item changed events for 10 seconds..."
WScript.Sleep 10*1000

WScript.Echo "Unsubscribing..."
Client.UnsubscribeMonitoredItem handle

WScript.Echo "Waiting for 5 seconds..."
WScript.Sleep 5 * 1000



Sub Client_DataChangeNotification(Sender, e)
    ' Display the data
    Dim display: If e.Exception Is Nothing Then display = e.AttributeData Else display = e.ErrorMessageBrief
    WScript.Echo display
End Sub
Requirements

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

See Also