Skip to main content

.NET / C# Local SDK Getting Started

Nuget GitHub

Initializing SDK

To start, initialize a client using the SDK key.

using System;
using System.Diagnostics;
using DevCycle.SDK.Server.Local.Api;

namespace Example {
public class Example {
static Main(string[] args) {
using DevCycleLocalClient client = new DevCycleLocalClientBuilder()
.SetSDKKey("<DEVCYCLE_SERVER_SDK_KEY>")
.Build();
}
}
}

Initialization With Callback

You can also setup a callback to be notified when the client is fully initialized and use DevCycleLocalOptions to further configure the client.

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using DevCycle.SDK.Server.Local.Api;
using DevCycle.SDK.Server.Common;
using Microsoft.Extensions.Logging;

namespace Example {
public class Example {
private static DevCycleLocalClient client;

static async Task Main(string[] args) {
client = new DevCycleLocalClientBuilder()
.SetSDKKey("<DEVCYCLE_SERVER_SDK_KEY>")
.SetOptions(new DevCycleLocalOptions(configPollingIntervalMs: 60000, eventFlushIntervalMs: 60000))
.SetInitializedSubscriber((o, e) => {
if (e.Success) {
ClientInitialized();
} else {
Console.WriteLine($"DevCycle Client did not initialize. Error: {e.Error}");
}
})
.SetLogger(LoggerFactory.Create(builder => builder.AddConsole()))
.Build();

try {
await Task.Delay(5000);
} catch (TaskCanceledException) {
System.Environment.Exit(0);
}
}

private static void ClientInitialized() {
// Start using the client here
}
}
}