Uh oh!
There was an error while loading. Please reload this page.
Add Process.StartAndForget APIs for fire-and-forget process launching - #126078
Conversation
Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/095d096c-d5d9-4ad1-b5f2-45fbadf30315
Tagging subscribers to this area: @dotnet/area-system-diagnostics-process |
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot address my feedback
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/942ffa7e-9504-40eb-9a58-9c4b6ceee3c1
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot address my feedback
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/71890478-dd77-4849-8278-bb3194c8489f
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot address my feedback
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…s on Unix Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/a8a7e105-927e-424f-986b-434912ec8a8e
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
danmoseley
commented
Apr 16, 2026
i only see API approval issue for |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
adamsitnik
commented
Apr 16, 2026
Please check #125838 (comment) @copilot please add this exact link to the PR description. And update the description based on the current state of the PR |
…tAndForget test Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/3564306f-64a4-473b-8bea-cce48f30b996 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
danmoseley
commented
Apr 16, 2026
Ah I thought api review always update the top post to final shape. ok |
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/cf4bd1f8-9847-4f51-996e-2434969a7a15 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Added the link #125838 (comment) to the PR description and updated it to reflect the current state of the PR. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Adds two new static methods to
Processfor scenarios where you want to launch a process, get its PID, and immediately release all resources without waiting for it to exit. API approved in #125838 (comment).Description
New APIs (
Process.Scenarios.cs):Process.StartAndForget(ProcessStartInfo)— validates thatUseShellExecuteis not set (throwsInvalidOperationExceptionifUseShellExecute = true, since on Windows shell execution may not create a new process, making it impossible to return a valid PID) and that no stream redirection is configured (throwsInvalidOperationExceptionif anyRedirectStandardInput/Output/Errorflag is set). Starts the process viaSafeProcessHandle.Start, releases all associated resources, and returns the PID. When no standard handles are provided viaProcessStartInfo.StandardInputHandle/StandardOutputHandle/StandardErrorHandle, they are redirected to the null device by default. When possible, handle inheritance is limited to the standard handles only.Process.StartAndForget(string fileName, IList<string>? arguments = null)— builds aProcessStartInfoand delegates to theProcessStartInfooverload above. No handles are inherited by the new process.Validation guards — throws
InvalidOperationExceptionif:UseShellExecute = true(shell execution may not start a new process on Windows, making it impossible to return a valid PID)RedirectStandardInput/Output/Errorflag is set (useProcessStartInfo.StandardInputHandle = File.OpenNullHandle()instead to redirect to null explicitly)Supporting changes:
SafeProcessHandle.Start(introduced in PR Introduce SafeProcessHandle.Start and ProcessId #126192) directly, avoiding the need to create and dispose aProcessinstance// this needs to come after the ios attribute due to limitations in the platform analyzercomment on[SupportedOSPlatformAttribute("maccatalyst")], consistent with otherStartoverloads in the fileStartAndForget_UseShellExecuteNotSupportedinStrings.resx; the redirect-not-supported error message (CantSetRedirectForSafeProcessHandleStart) mentions bothSafeProcessHandle.StartandProcess.StartAndForgetso users calling either API get a clear, actionable error: "The RedirectStandardInput, RedirectStandardOutput, and RedirectStandardError properties cannot be used by SafeProcessHandle.Start or Process.StartAndForget. Use the StandardInputHandle, StandardOutputHandle, and StandardErrorHandle properties."boolparameter onSafeProcessHandle.Start(ProcessStartInfo, bool)renamed fromredirectToNulltofallbackToNullfor clarityusing System.IOandusing System.Runtime.InteropServicesdirectives removed fromProcess.Scenarios.cs<summary>XML docs on bothStartAndForgetoverloads clearly describe the fire-and-forget semantics (starts the process, releases resources, and returns the PID)<remarks>paragraphs inStartAndForget(ProcessStartInfo)reordered: the standard-handle redirect paragraph is first, followed by the handle-inheritance paragraphProcess.Scenarios.csadded toSystem.Diagnostics.Process.csprojStartAndForget.cs:[ConditionalTheory]parameterized bybool useProcessStartInfo, usingCreateSleepProcesswith a 1-hour timeout andusingdeclaration, with explicitKill()/WaitForExit()cleanup intry/finallyStartAndForget_WithStandardOutputHandle_CapturesOutputuses theCreateProcess/RemoteExecutor pattern withSafeFileHandle.CreateAnonymousPipeto verify thatArgumentListis not ignored and thatStandardOutputHandlecorrectly captures process output — mirrors theCanRedirectOutputToPipepattern fromProcessHandlesTestsArgumentNullExceptiontests useAssertExtensions.Throwsto verify parameter names ("startInfo"and"fileName")InvalidOperationExceptionfor each redirect flag combination and forUseShellExecute = truevia[Theory]cmd.exeon Windows (available on Nano Server) andtrueon Unix⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.