---
source_url: https://www.pubnub.com/docs/sdks/c-sharp/api-reference/misc
title: Utility Methods API for C# SDK
updated_at: 2026-06-19T11:36:50.644Z
sdk_name: PubNub C# SDK
sdk_version: 8.3.0
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Utility Methods API for C# SDK

PubNub C# SDK, use the latest version: 8.3.0

Install:

```bash
dotnet add package PubNub@8.3.0
```

The methods on this page are utility methods that don't fit into other categories.

:::tip Request execution
Use `try`/`catch` when working with the C# SDK.
If a request has invalid parameters (for example, a missing required field), the SDK throws an exception. If the request reaches the server but fails (server error or network issue), the error details are available in the returned `status`.
```csharp
try
{
    PNResult<PNPublishResult> publishResponse = await pubnub.Publish()
        .Message("Why do Java developers wear glasses? Because they can't C#.")
        .Channel("my_channel")
        .ExecuteAsync();
    PNStatus status = publishResponse.Status;
    Console.WriteLine("Server status code : " + status.StatusCode.ToString());
}
catch (Exception ex)
{
    Console.WriteLine($"Request can't be executed due to error: {ex.Message}");
}
```
:::

## Destroy

Destroy frees up the threads and allows for clean exit.

### Method(s)

```csharp
destroy()
```

### Sample code

:::tip Reference code
This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.
:::

```csharp
using PubnubApi;

// Configuration
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize PubNub
Pubnub pubnub = new Pubnub(pnConfiguration);
        
// Destroy PubNub instance to clean up resources
pubnub.Destroy();

Console.WriteLine("PubNub instance destroyed successfully.");
```

### Returns

None

## Disconnect

Call the `Disconnect` method to force the SDK to stop all requests to PubNub server when there are active subscribe channels.

### Method(s)

To `disconnect` the data transmission you can use the following method(s) in C# SDK.

```csharp
Disconnect<T>()
```

This method doesn't take any arguments.

### Sample code

```csharp
using PubnubApi;

// Configuration
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize PubNub
Pubnub pubnub = new Pubnub(pnConfiguration);
        
pubnub.Disconnect<string>();
```

## Get subscribed channel groups

Returns all the subscribed channel groups in a `List of type String`.

### Method(s)

To `Get Subscribe Channel Groups` you can use the following method(s) in the C# SDK:

```csharp
List<string> GetSubscribedChannelGroups()
```

### Sample code

#### Get subscribed channel groups

```csharp
using PubnubApi;

// Configuration
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize PubNub
Pubnub pubnub = new Pubnub(pnConfiguration);
        
List<string> groups = pubnub.GetSubscribedChannelGroups();
```

### Response

`List<String>`

```json
["channelGroup1", "channelGroup2"]
```

## Get subscribed channels

Returns all the subscribed channels in a `List of type String`.

### Method(s)

To `Get Subscribed Channels` you can use the following method(s) in the C# SDK:

```csharp
List<string> GetSubscribedChannels()
```

### Sample code

#### Get subscribed channels

```csharp
using PubnubApi;

// Configuration
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize PubNub
Pubnub pubnub = new Pubnub(pnConfiguration);
        
List<string> channels = pubnub.GetSubscribedChannels();
```

### Response

`List<String>`

```json
["channel1", "channel2"]
```

## Reconnect

Call the `reconnect` method to force the SDK to try and reach out PubNub.

### Method(s)

To `reconnect` the data you can use the following method(s) in C# SDK.

```csharp
Reconnect<T>(bool resetSubscribeToken)
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| resetSubscribeToken | bool | Optional |  | Passing `true` will send zero timetoken upon reconnect. |

### Sample code

```csharp
using PubnubApi;

// Configuration
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize PubNub
Pubnub pubnub = new Pubnub(pnConfiguration);
        
pubnub.Reconnect<string>();
```