Execute not blocking async shell command in C#

note, May 22, 2023, on Mitja Felicijan's blog

Execute a shell command in async in C# while not blocking the UI thread.

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().

private async void button_Click(object sender, EventArgs e)
{
  await executeCopyCommand();
}

Other notes

DateTitle
Change permissions of matching files recursively
Download list of YouTube files
Push to multiple origins at once in Git
Set color temperature of displays on i3
Use option key as meta in Alacritty under macOS
Install Plan9port on Linuxplan9
Extend Lua with custom C functions using Clangc
Easy measure time took in a bash script
Male and female body proportion reference images3d
Alacritty open links with modifier
Fix screen tearing on Debian 12 Xorg and i3
Make B/W SVG charts with matplotlib
Dungeon Crawl Stone Soup - New player guidedcss
My brand new Plan9/9front desktopplan9
Using ffmpeg to combine videos side by side