Utility Methods API for C# SDK

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

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.

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)

destroy()

Sample code

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.

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.

Disconnect<T>()

This method doesn't take any arguments.

Sample code


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:

List<string> GetSubscribedChannelGroups()

Sample code

Get subscribed channel groups


Response

List<String>

["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:

List<string> GetSubscribedChannels()

Sample code

Get subscribed channels


Response

List<String>

["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.

Reconnect<T>(bool resetSubscribeToken)
* required
ParameterDescription
resetSubscribeToken
Type: bool
Passing true will send zero timetoken upon reconnect.

Sample code


Last updated on