QuickOPC User's Guide and Reference
ServerConditionChanged Event (IEasyUAClient)

OpcLabs.EasyOpcUA Assembly > OpcLabs.EasyOpc.UA Namespace > IEasyUAClient Interface : ServerConditionChanged Event
Raised for a change in the condition of an OPC server.
Event ServerConditionChanged As EasyUAServerConditionChangedEventHandler
Dim instance As IEasyUAClient
Dim handler As EasyUAServerConditionChangedEventHandler
AddHandler instance.ServerConditionChanged, handler
event EasyUAServerConditionChangedEventHandler ServerConditionChanged
event EasyUAServerConditionChangedEventHandler^ ServerConditionChanged
Event Data

The event handler receives an argument of type EasyUAServerConditionChangedEventArgs containing data related to this event. The following EasyUAServerConditionChangedEventArgs properties provide information specific to this event.

Indicates whether the object is now connected. (Inherited from OpcLabs.BaseLib.Communication.ConnectedConditionChangedEventArgs)
Indicates the state of the connection. (Inherited from OpcLabs.BaseLib.Communication.ConnectedConditionChangedEventArgs)
Default endpoint descriptor.  
Diagnostics information (such as warnings) assembled during the operation. (Inherited from OpcLabs.BaseLib.OperationModel.OperationEventArgs)
Count of diagnostic information elements assembled during the operation. (Inherited from OpcLabs.BaseLib.OperationModel.OperationEventArgs)
Textual summary of diagnostics information, one message per line. (Inherited from OpcLabs.BaseLib.OperationModel.OperationEventArgs)
Contains the endpoint descriptor, i.e. the data defining a connection to the OPC-UA Server (mainly, its URL string).  
Gets or sets the error ID of the error. (Inherited from OpcLabs.BaseLib.OperationModel.OperationEventArgs)
Gets or sets a message that describes the current exception. (Inherited from OpcLabs.BaseLib.OperationModel.OperationEventArgs)
The first line of the error message. (Inherited from OpcLabs.BaseLib.OperationModel.OperationEventArgs)
Gets the current exception. Contains null reference when no exception. (Inherited from OpcLabs.BaseLib.OperationModel.OperationEventArgs)
A normalized OpcLabs.BaseLib.OperationModel.OperationEventArgs.Diagnostics collection. (Inherited from OpcLabs.BaseLib.OperationModel.OperationEventArgs)
A normalized OpcLabs.BaseLib.OperationModel.OperationEventArgs.Exception object, or null if there was no error. (Inherited from OpcLabs.BaseLib.OperationModel.OperationEventArgs)
When disconnected, time to next reconnection attempt. In milliseconds. (Inherited from OpcLabs.BaseLib.Communication.ConnectedConditionChangedEventArgs)
Gets or sets statistics for the connected condition at the moment the event was generated. (Inherited from OpcLabs.BaseLib.Communication.ConnectedConditionChangedEventArgs)
Status information corresponding to the contents of the event arguments. (Inherited from OpcLabs.BaseLib.Communication.ConnectedConditionChangedEventArgs)
Gets indication whether the operation has succeeded. (Inherited from OpcLabs.BaseLib.OperationModel.OperationEventArgs)
// This example shows how to monitor connections to and disconnections from the OPC UA server.

using System;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.OperationModel;

namespace UADocExamples._EasyUAClient
    class ServerConditionChanged
        public static void Main1()
            UAEndpointDescriptor endpointDescriptor =
            // or "http://opcua.demo-this.com:51211/UA/SampleServer" (not in .NET Standard)
            // or "https://opcua.demo-this.com:51212/UA/SampleServer/"

            // Instantiate the client object and hook events
            using (var client = new EasyUAClient())
                client.DataChangeNotification += client_DataChangeNotification;
                client.ServerConditionChanged += client_ServerConditionChanged;

                    Console.WriteLine("Reading (1)");
                    // The first read will cause a connection to the server.
                    UAAttributeData attributeData1 = client.Read(endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10853");

                    Console.WriteLine("Reading (2)");
                    // The second read, because it closely follows the first one, will reuse the connection that is already
                    // open.
                    UAAttributeData attributeData2 = client.Read(endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10853");
                catch (UAException uaException)
                    Console.WriteLine("*** Failure: {0}", uaException.GetBaseException().Message);

                Console.WriteLine("Waiting for 10 seconds...");
                // Since the connection is now not used for some time, it will be closed.
                System.Threading.Thread.Sleep(10 * 1000);

                // Subscribing to a monitor item will cause a connection to the server, if one is not yet open.
                client.SubscribeDataChange(endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10853", 1000);

                Console.WriteLine("Waiting for 10 seconds...");
                // The connection will not be closed as long as there are any subscriptions to the server.
                System.Threading.Thread.Sleep(10 * 1000);


                Console.WriteLine("Waiting for 10 seconds...");
                // After some delay, the connection will be closed, because there are no subscriptions to the server.
                System.Threading.Thread.Sleep(10 * 1000);


        static void client_DataChangeNotification(object sender, EasyUADataChangeNotificationEventArgs e)
            // Display value
            if (e.Succeeded)
                Console.WriteLine("Value: {0}", e.AttributeData.Value);
                Console.WriteLine("*** Failure: {0}", e.ErrorMessageBrief);

        static void client_ServerConditionChanged(object sender, EasyUAServerConditionChangedEventArgs e)
            // Display the event

        // Example output:
        //"opc.tcp://opcua.demo-this.com:51210/UA/SampleServer" Connecting; Success
        //"opc.tcp://opcua.demo-this.com:51210/UA/SampleServer" Connected; Success
        //-8.095801E+32 {System.Single} @2021-06-24T07:09:46.062 @@2021-06-24T07:09:46.062; Good
        //-3.11389E-18 {System.Single} @2021 - 06 - 24T07: 09:46.125 @@2021 - 06 - 24T07: 09:46.125; Good
        //Waiting for 10 seconds...
        //"opc.tcp://opcua.demo-this.com:51210/UA/SampleServer" Disconnecting; Success
        //"opc.tcp://opcua.demo-this.com:51210/UA/SampleServer" Disconnected(Infinite); Success
        //"opc.tcp://opcua.demo-this.com:51210/UA/SampleServer" Connecting; Success
        //Waiting for 10 seconds...
        //"opc.tcp://opcua.demo-this.com:51210/UA/SampleServer" Connected; Success
        //Value: 3.293034E-31
        //Value: 6.838126E+37
        //Value: 5.837702E-29
        //Value: 0.02940081
        //Value: -9.653872E-17
        //Value: -1.012749E+29
        //Value: -1.422391E+20
        //Value: -3.56571E-22
        //Waiting for 10 seconds...
        //"opc.tcp://opcua.demo-this.com:51210/UA/SampleServer" Disconnecting; Success
        //"opc.tcp://opcua.demo-this.com:51210/UA/SampleServer" Disconnected(Infinite); Success

Target Platforms: .NET Framework: Windows 10, Windows Server 2012, Windows Server 2016; .NET Core, .NET 5: Linux, macOS, Microsoft Windows

See Also