private async Task RunSlnGenAsync()

in src/Microsoft.VisualStudio.SlnGen.Extension/SlnGenPackage.cs [103:141]


        private async Task<int> RunSlnGenAsync(string project, CancellationToken cancellationToken)
        {
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            using SemaphoreSlim semaphore = new SemaphoreSlim(0, 1);

            using Process process = new Process
            {
                EnableRaisingEvents = true,
                StartInfo = new ProcessStartInfo
                {
                    FileName = "slngen.exe",
                    Arguments = string.Join(
                        " ",
                        $"\"{project}\"",
                        "--launch:false"),
                    UseShellExecute = false,
                    CreateNoWindow = true,
                    RedirectStandardError = false,
                    RedirectStandardInput = false,
                    RedirectStandardOutput = false,
                },
            };

            process.Exited += (_, _) => semaphore.Release();

            process.Start();

            try
            {
                await semaphore.WaitAsync(cancellationToken);

                return process.ExitCode;
            }
            catch (OperationCanceledException)
            {
                return 0;
            }
        }