From 4ecfc1fb9f62044afde61f37eade68d6decb0e96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Marchal?= Date: Wed, 15 Mar 2023 18:16:40 +0100 Subject: [PATCH] Add a C# snippet for async tasks being run from the UI --- async-from-ui.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 async-from-ui.cs diff --git a/async-from-ui.cs b/async-from-ui.cs new file mode 100644 index 0000000..856643d --- /dev/null +++ b/async-from-ui.cs @@ -0,0 +1,16 @@ +// Basic function handling to having async tasks being run from an interface action in C# WPF. + +private async void Clicked(object sender, RoutedEventArgs e) +{ + await Function(); +} + +public async Task Function() +{ + await Task.Run(async () => + { + await someCommand(); + }); + + UI_things(); +} \ No newline at end of file