Sprog

Process.StartAndForget Method

Definition

Overloads

Name Description
StartAndForget(ProcessStartInfo)

Starts the process described by startInfo, releases all associated resources, and returns the process ID.

StartAndForget(String, IEnumerable<String>)

Starts a process with the specified file name and optional arguments, releases all associated resources, and returns the process ID.

StartAndForget(ProcessStartInfo)

Source:
Process.Scenarios.cs

Starts the process described by startInfo, releases all associated resources, and returns the process ID.

public:
 static int StartAndForget(System::Diagnostics::ProcessStartInfo ^ startInfo);
[System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static int StartAndForget(System.Diagnostics.ProcessStartInfo startInfo);
[<System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
static member StartAndForget : System.Diagnostics.ProcessStartInfo -> int
Public Shared Function StartAndForget (startInfo As ProcessStartInfo) As Integer

Parameters

startInfo
ProcessStartInfo

The ProcessStartInfo that contains the information used to start the process.

Returns

The process ID of the started process.

Attributes

Exceptions

startInfo is null.

One or more of RedirectStandardInput, RedirectStandardOutput, or RedirectStandardError is set to true. Stream redirection is not supported in fire-and-forget scenarios because redirected streams must be drained to avoid deadlocks.

-or-

UseShellExecute is set to true. Shell execution is not supported in fire-and-forget scenarios because on Windows it might not create a new process, making it impossible to return a valid process ID.

Remarks

When a standard handle (StandardInputHandle, StandardOutputHandle, or StandardErrorHandle) is not provided, it is redirected to the null file by default.

This method is designed for fire-and-forget scenarios where the caller wants to launch a process and does not need to interact with it further. It starts the process, releases all associated resources, and returns the process ID. The started process continues to run independently.

Applies to

StartAndForget(String, IEnumerable<String>)

Source:
Process.Scenarios.cs

Starts a process with the specified file name and optional arguments, releases all associated resources, and returns the process ID.

[System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static int StartAndForget(string fileName, System.Collections.Generic.IEnumerable<string>? arguments = default);
[<System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
static member StartAndForget : string * seq<string> -> int
Public Shared Function StartAndForget (fileName As String, Optional arguments As IEnumerable(Of String) = Nothing) As Integer

Parameters

fileName
String

The name of the executable to start.

arguments
IEnumerable<String>

The command-line arguments to pass to the process. Pass null or an empty sequence to start the process without additional arguments.

Returns

The process ID of the started process.

Attributes

Exceptions

fileName is null.

fileName is empty.

Remarks

This method is designed for fire-and-forget scenarios where the caller wants to launch a process and does not need to interact with it further. It starts the process, captures its process ID, releases all associated resources, and returns the process ID. The started process continues to run independently.

Standard handles are redirected to the null file by default.

Applies to