Utility Methods API for C# SDK
The methods on this page are utility methods that don't fit into other categories.
Request execution
We recommend using try
and catch
statements when working with the C# SDK.
If there's an issue with the provided API parameter values, like missing a required parameter, the SDK throws an exception. However, if there is a server-side API execution issue or a network problem, the error details are contained within the 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
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)
Parameter | Description |
---|---|
resetSubscribeToken Type: bool | Passing true will send zero timetoken upon reconnect. |
Sample code