From cd6644ea4ddc78597934ab0ef5ba50e3c3daa927 Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Sat, 8 Jul 2023 23:25:41 +0200 Subject: Moved to a simpler SSG --- content/notes/non-blocking-shell-exec-csharp.md | 44 ------------------------- 1 file changed, 44 deletions(-) delete mode 100644 content/notes/non-blocking-shell-exec-csharp.md (limited to 'content/notes/non-blocking-shell-exec-csharp.md') diff --git a/content/notes/non-blocking-shell-exec-csharp.md b/content/notes/non-blocking-shell-exec-csharp.md deleted file mode 100644 index 1904c4d..0000000 --- a/content/notes/non-blocking-shell-exec-csharp.md +++ /dev/null @@ -1,44 +0,0 @@ ---- -title: Execute not blocking async shell command in C# -url: non-blocking-shell-exec-csharp.html -date: 2023-05-22T12:00:00+02:00 -type: notes -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