This example shows the managed API path built around NativeMessageBoxClient.
using System;
using System.Threading.Tasks;
using NativeMessageBox;
static async Task<int> Main()
{
NativeMessageBoxClient.ConfigureHost(options =>
{
options.RequireStaThreadForWindows = true;
});
NativeMessageBoxClient.RegisterLogHandler(message =>
{
Console.WriteLine($"[NativeMessageBox] {message}");
});
var options = new MessageBoxOptions(
message: "Delete generated files before rebuilding?",
buttons:
[
new MessageBoxButton(100, "Delete", MessageBoxButtonKind.Destructive, isDefault: true),
new MessageBoxButton(0, "Cancel", MessageBoxButtonKind.Secondary, isCancel: true)
],
title: "Clean Output",
icon: MessageBoxIcon.Warning,
verificationText: "Do not ask again",
showSuppressCheckbox: true,
timeout: TimeSpan.FromSeconds(20),
timeoutButtonId: 0);
MessageBoxResult result = await NativeMessageBoxClient.ShowAsync(options);
if (result.Outcome == MessageBoxOutcome.Success && result.ButtonId == 100)
{
Console.WriteLine("Proceed with cleanup.");
}
return 0;
}
ShowOrThrow when non-success outcomes should be exceptional in your application flowOn Windows, advanced dialog features may require an STA thread. The managed host exposes that through RequireStaThreadForWindows, and MessageBoxOptions.PlatformCapabilities lets you inspect whether a given request needs that path.