From 1100562e29f6476448b656dbddd4cf22505523f6 Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Sun, 10 Mar 2024 14:59:14 +0100 Subject: Move back to JBMAFP --- .../2023-05-22-non-blocking-shell-exec-csharp.md | 45 ---------------------- 1 file changed, 45 deletions(-) delete mode 100644 _posts/notes/2023-05-22-non-blocking-shell-exec-csharp.md (limited to '_posts/notes/2023-05-22-non-blocking-shell-exec-csharp.md') diff --git a/_posts/notes/2023-05-22-non-blocking-shell-exec-csharp.md b/_posts/notes/2023-05-22-non-blocking-shell-exec-csharp.md deleted file mode 100644 index f8b9c53..0000000 --- a/_posts/notes/2023-05-22-non-blocking-shell-exec-csharp.md +++ /dev/null @@ -1,45 +0,0 @@ ---- -title: Execute not blocking async shell command in C# -permalink: /non-blocking-shell-exec-csharp.html -date: 2023-05-22T12:00:00+02:00 -layout: post -type: note -draft: false -tags: [csharp] ---- - -Execute a shell command in async in C# while not blocking the UI thread. - -```c# -private async Task executeCopyCommand() -{ - await Task.Run(() => - { - var processStartInfo = new ProcessStartInfo("cmd", "/c dir") - { - RedirectStandardOutput = true, - UseShellExecute = false, - CreateNoWindow = true - }; - - var process = new Process - { - StartInfo = processStartInfo - }; - - process.Start(); - process.WaitForExit(); - }); -} -``` - -Make sure that `async` is present in the function definition and `await` is used -in the method that calls `executeCopyCommand()`. - -```c# -private async void button_Click(object sender, EventArgs e) -{ - await executeCopyCommand(); -} -``` - -- cgit v1.2.3