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.

1try
2{
3 PNResult<PNPublishResult> publishResponse = await pubnub.Publish()
4 .Message("Why do Java developers wear glasses? Because they can't C#.")
5 .Channel("my_channel")
6 .ExecuteAsync();
7
8 PNStatus status = publishResponse.Status;
9
10 Console.WriteLine("Server status code : " + status.StatusCode.ToString());
11}
12catch (Exception ex)
13{
14 Console.WriteLine($"Request can't be executed due to error: {ex.Message}");
15}

Destroy​

Destroy frees up the threads and allows for clean exit.

Method(s)​

1destroy()

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.
1

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.

1Disconnect<T>()

This method doesn't take any arguments.

Sample code​

1

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:

1List<string> GetSubscribedChannelGroups()

Sample code​

Get subscribed channel groups​

1

Response​

List<String>

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

1List<string> GetSubscribedChannels()

Sample code​

Get subscribed channels​

1

Response​

List<String>

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

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

Sample code​

1

Was this page useful?

Last updated on