.NET (C#)
Add the SDK to a C# desktop app on Windows, macOS or Linux: WinForms, WPF, Avalonia, a console app or a background service. Before you start, get your account approved and create an SDK key (steps 1 and 2 of the overview).
| Downloads | Language bindings (for csharp/IdlePay.cs) plus the library for each OS below, from your SDK page (approved accounts only) |
| Requires | .NET 6 or later |
| Namespace | IdlePay (classes Sdk, Options, State) |
| Your app runs on | Package | Library file | Runtime ID |
|---|---|---|---|
| Windows (64-bit) | windows-amd64 | idlepay.dll | win-x64 |
| macOS (Apple silicon and Intel) | macos | libidlepay.dylib | osx-arm64, osx-x64 |
| Linux x86-64 | linux-amd64 | libidlepay.so | linux-x64 |
| Linux ARM64 | linux-arm64 | libidlepay.so | linux-arm64 |
| Linux ARMv7 (32-bit) | linux-armv7 | libidlepay.so | linux-arm |
On Windows the library is 64-bit x86 only. Build your app for win-x64 (or set <PlatformTarget>x64</PlatformTarget>): a 32-bit or ARM64 process can't load it.
1. Add the files to your project
- Copy
IdlePay.csinto your project. - Put the library files in a folder of your project, for example
native/. - Copy the library next to your app's executable when you build. For a Windows-only app:
<ItemGroup> <None Include="native\idlepay.dll" Link="idlepay.dll" CopyToOutputDirectory="PreserveNewest" /> </ItemGroup>
For several systems, keep one folder per runtime ID and copy the one you publish for (dotnet publish -r osx-arm64 and so on):
<ItemGroup>
<None Include="native\win-x64\idlepay.dll" Link="idlepay.dll" CopyToOutputDirectory="PreserveNewest"
Condition="'$(RuntimeIdentifier)' == 'win-x64'" />
<None Include="native\osx\libidlepay.dylib" Link="libidlepay.dylib" CopyToOutputDirectory="PreserveNewest"
Condition="$(RuntimeIdentifier.StartsWith('osx'))" />
<None Include="native\linux-x64\libidlepay.so" Link="libidlepay.so" CopyToOutputDirectory="PreserveNewest"
Condition="'$(RuntimeIdentifier)' == 'linux-x64'" />
<None Include="native\linux-arm64\libidlepay.so" Link="libidlepay.so" CopyToOutputDirectory="PreserveNewest"
Condition="'$(RuntimeIdentifier)' == 'linux-arm64'" />
</ItemGroup>
The macOS library works on both Apple silicon and Intel.
2. Ask the user, and remember the answer
Keep the user's choice and the SDK calls in one small class. Put your SDK key in SdkKey:
using System;
using System.IO;
static class Sharing
{
const string SdkKey = "ipsk_..."; // from the SDK page of your dashboard
// A per-user folder of your app that isn't synced to other computers.
static readonly string AppDir = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "MyApp");
static readonly string ConsentFile = Path.Combine(AppDir, "sharing-consent.txt");
public static bool Asked => File.Exists(ConsentFile);
public static bool Allowed => Asked && File.ReadAllText(ConsentFile).StartsWith("allowed");
// The user clicked "Allow".
public static void Allow()
{
Save("allowed");
Start();
}
// The user clicked "No thanks", or turned sharing off in your settings.
public static void Decline()
{
Save("declined");
IdlePay.Sdk.Stop();
}
public static void Start() => IdlePay.Sdk.Start(new IdlePay.Options
{
Key = SdkKey,
DataDir = Path.Combine(AppDir, "idlepay"),
Consent = true,
});
static void Save(string answer)
{
Directory.CreateDirectory(AppDir);
File.WriteAllText(ConsentFile, $"{answer} {DateTime.UtcNow:o} disclosure-v1");
}
}
Show your consent dialog once (see sample wording). For example, in WPF:
if (!Sharing.Asked)
{
var answer = MessageBox.Show(
"With your permission, My App shares a small part of your unused internet connection with IdlePay. ...",
"Support My App by sharing your connection", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No);
if (answer == MessageBoxResult.Yes) Sharing.Allow(); else Sharing.Decline();
}
Add a setting that calls Sharing.Allow() or Sharing.Decline(), so users can change their mind. Also keep a consent record.
3. Start it on launch, stop it on exit
// When your app starts: if (Sharing.Allowed) Sharing.Start(); // When it exits: AppDomain.CurrentDomain.ProcessExit += (_, _) => IdlePay.Sdk.Stop();
Startreturns at once; the SDK runs on its own threads. It throwsInvalidOperationExceptionwith the reason if it can't start, for example "already started".Stopwaits a few seconds at most.- Sharing runs while your app runs. An app that lives in the tray or runs at login earns more hours than one that's opened now and then.
- Only one running copy of your app can share from the same
DataDir. A second copy reports "another copy of this app is already sharing from this data folder".
4. Check that it works
var s = IdlePay.Sdk.Status();
Console.WriteLine($"{s.Value}: {s.Message} (device {s.DeviceId}, IP {s.PublicIp})");
On a computer on a home connection, Value should be online within about a minute, and the device appears on your SDK page. Anything else comes with a Message that says why: see the messages. A DllNotFoundException means the library isn't next to your executable, or is for another system or CPU.
5. Pause and reconnect
IdlePay.Sdk.SetPaused(true); // your own reason: on battery, a metered connection, a game running... IdlePay.Sdk.SetPaused(false); IdlePay.Sdk.Reconnect(); // optional: the network changed, reconnect now
To cap traffic per device, set MaxDailyMB in Options. Sharing then pauses until midnight UTC once the device has shared that much.
6. Ship it
- Make sure your installer includes the library next to the executable.
- macOS: sign
libidlepay.dylibwith your Developer ID along with your app, before notarizing. A library downloaded with a browser is quarantined: while testing, clear it withxattr -d com.apple.quarantine libidlepay.dylib. - Windows: if you sign your app, you can sign
idlepay.dllwith the same certificate.
Updating the SDK
Replace IdlePay.cs and the libraries with the new version's and release your app. Devices keep their link to your account.