1---
 2title: Execute not blocking async shell command in C#
 3url: non-blocking-shell-exec-csharp.html
 4date: 2023-05-22T12:00:00+02:00
 5type: note
 6draft: false
 7---
 8
 9Execute a shell command in async in C# while not blocking the UI thread.
10
11```c#
12private async Task executeCopyCommand()
13{
14  await Task.Run(() =>
15  {
16    var processStartInfo = new ProcessStartInfo("cmd", "/c dir")
17    {
18      RedirectStandardOutput = true,
19      UseShellExecute = false,
20      CreateNoWindow = true
21    };
22
23    var process = new Process
24    {
25      StartInfo = processStartInfo
26    };
27
28    process.Start();
29    process.WaitForExit();
30  });
31}
32```
33
34Make sure that `async` is present in the function definition and `await` is used
35in the method that calls `executeCopyCommand()`.
36
37```c#
38private async void button_Click(object sender, EventArgs e)
39{
40  await executeCopyCommand();
41}
42```
43