The Windows App SDK empowers all Windows desktop apps with modern Windows UI, APIs, and platform features, including back-compat support, shipped via NuGet.
I'm adding my own notes here, so they're searchable.
I had followed Making the app single-instanced (Part 3) to make my C# WinAppSDK app single-instanced. Part of that blog makes the Mainasync. So it looked like this:
// kids, don't try this at home
[STAThread]
static async Task<int> Main(string[] args)
{
Then I added a Windows Community Toolkit MarkdownTextBlock. I set IsTextSelectionEnabled="True" on that text block. When I went to copy text from that text block, I'd always crash, with
I'm adding my own notes here, so they're searchable.
I had followed Making the app single-instanced (Part 3) to make my C# WinAppSDK app single-instanced. Part of that blog makes the
Main
async. So it looked like this:Then I added a Windows Community Toolkit
MarkdownTextBlock
. I setIsTextSelectionEnabled="True"
on that text block. When I went to copy text from that text block, I'd always crash, withTurns out,
async
Main
s are considered harmful. Not only that, but doing this would have also broken Narrator.As it also turns out, the actual samples repo doesn't make
Main
async either! https://github.com/microsoft/WindowsAppSDK-Samples/blob/ba29b02e9f529baea5e3015f7cb224a5c8447e6a/Samples/AppLifecycle/Instancing/cs2/cs-winui-packaged/CsWinUiDesktopInstancing/CsWinUiDesktopInstancing/Program.cs#L29-L33