# OpcClientApplication&lt;T&gt; Members

> Reference: Provides a base class for applications which host a client of the type T and connect it to the server when the application is run.

<dl class="api-definition">
<dt>Type</dt>
<dd><a href="./">OpcClientApplication&lt;T&gt;</a></dd>
<dt>Namespace</dt>
<dd><a href="../namespaces/opc.uafx.client">Opc.UaFx.Client</a></dd>
<dt>Assembly</dt>
<dd>Opc.UaFx.Advanced.dll</dd>
<dt>Package</dt>
<dd>Opc.UaFx.Advanced v2.59.0</dd>
<dt>Also in</dt>
<dd>Opc.UaFx.Client</dd>
</dl>

Inherits members from [OpcApplication](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcapplication/members).

## Constructors

### OpcClientApplication

<span class="api-meta">2 overloads</span>

| Overload | Description |
|---|---|
| [OpcClientApplication()](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcclientapplication-1/members#opcclientapplication-noparams) | Initializes a new instance of the [OpcClientApplication&lt;T&gt;](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcclientapplication-1/) class which hosts a new instance of the type `T`. |
| [OpcClientApplication(T)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcclientapplication-1/members#opcclientapplication-t0) | Initializes a new instance of the [OpcClientApplication&lt;T&gt;](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcclientapplication-1/) class using the `client` specified. |

**Exceptions (all overloads)**

| Exception | Condition |
|---|---|
| [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception) | An application has already been created on the current thread and has not yet been exited (see [Current](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcapplication/members#current)). |

#### OpcClientApplication()

Initializes a new instance of the [OpcClientApplication&lt;T&gt;](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcclientapplication-1/) class which hosts a new instance of the type `T`.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcClientApplication()
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Sub New()
```

</div>

#### OpcClientApplication(T)

Initializes a new instance of the [OpcClientApplication&lt;T&gt;](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcclientapplication-1/) class using the `client` specified.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcClientApplication(T client)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Sub New(client As T)
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `client` | T | The client to host. |

**Exceptions**

| Exception | Condition |
|---|---|
| [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception) | The `client` is a null reference (Nothing in Visual Basic). |

## Properties

### Client

Gets the client hosted by the application.

<div class="api-signature" data-lang="csharp">

```csharp
public T Client { get; }
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public ReadOnly Property Client As T
```

</div>

**Property value**

T

The instance of the type `T` hosted by the application.

### Configuration

<span class="api-meta">override</span>

Gets the configuration of the [Client](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcclientapplication-1/members#client).

<div class="api-signature" data-lang="csharp">

```csharp
public override OpcApplicationConfiguration Configuration { get; }
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Overrides ReadOnly Property Configuration As OpcApplicationConfiguration
```

</div>

**Property value**

[OpcApplicationConfiguration](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcapplicationconfiguration/)

The [Configuration](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcclient/configuration) of the [Client](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcclientapplication-1/members#client).

**Overrides**

[Configuration](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcapplication/members#configuration)

## Methods

### ExitCore

<span class="api-meta">protected · override</span>

Disconnects the [Client](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcclientapplication-1/members#client) from the server and raises the [Exiting](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcapplication/members#exiting) and [Exited](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcapplication/members#exited) events.

<div class="api-signature" data-lang="csharp">

```csharp
protected override void ExitCore()
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Protected Overrides Sub ExitCore()
```

</div>

**Overrides**

[ExitCore](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcapplication/members#exitcore)

**Remarks**

The method disconnects the [Client](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcclientapplication-1/members#client) and raises the events only if the [State](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcclient/state) of the [Client](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcclientapplication-1/members#client) is [Connecting](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcclientstate/#connecting), [Connected](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcclientstate/#connected), [Reconnecting](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcclientstate/#reconnecting) or [Reconnected](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcclientstate/#reconnected). While the client connects, the method waits until connecting has completed. In a non-interactive environment (see [UserInteractive](https://learn.microsoft.com/dotnet/api/system.environment.userinteractive)) the method ends a waiting [Run](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcapplication/members#run) in any state, e.g. also if the client has been disconnected because reconnecting failed.

### LoadConfigurationCore

<span class="api-meta">protected · override</span>

Loads the client configuration from the configuration section with the `configSectionName` specified and assigns it to the [Client](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcclientapplication-1/members#client).

<div class="api-signature" data-lang="csharp">

```csharp
protected override void LoadConfigurationCore(string configSectionName)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Protected Overrides Sub LoadConfigurationCore(configSectionName As String)
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `configSectionName` | [String](https://learn.microsoft.com/dotnet/api/system.string) | The name of the configuration section or a null reference (Nothing in Visual Basic) to use the full name of the type `T`. |

**Overrides**

[LoadConfigurationCore](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcapplication/members#loadconfigurationcore)

### RunCore

<span class="api-meta">protected · override</span>

Connects the [Client](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcclientapplication-1/members#client) to the server and waits until the application exits.

<div class="api-signature" data-lang="csharp">

```csharp
protected override int RunCore()
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Protected Overrides Function RunCore() As Integer
```

</div>

**Returns**

[Int32](https://learn.microsoft.com/dotnet/api/system.int32)

The [ExitCode](https://learn.microsoft.com/dotnet/api/system.environment.exitcode).

**Exceptions**

| Exception | Condition |
|---|---|
| [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception) | The [Client](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcclientapplication-1/members#client) is connecting or connected to the server. |

**Overrides**

[RunCore](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcapplication/members#runcore)

**Remarks**

The method connects the client only in the state [Created](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcclientstate/#created) or [Disconnected](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcclientstate/#disconnected); in any other state it returns at once. In an interactive environment (see [UserInteractive](https://learn.microsoft.com/dotnet/api/system.environment.userinteractive)) the method reports the result on the console, waits for a key and exits the application. Otherwise the method returns at once if connecting failed, without passing on the exception, and else waits until the application is exited.
