Process.RunAsync 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
重载
| 名称 | 说明 |
|---|---|
| RunAsync(ProcessStartInfo, CancellationToken) |
异步启动其 |
| RunAsync(String, IEnumerable<String>, Boolean, CancellationToken) |
异步启动具有指定文件名和可选参数的进程,等待其退出,并返回其退出状态。 |
RunAsync(ProcessStartInfo, CancellationToken)
- Source:
- Process.Scenarios.cs
异步启动其 startInfo描述的过程,等待其退出,并返回其退出状态。
[System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static System.Threading.Tasks.Task<System.Diagnostics.ProcessExitStatus> RunAsync(System.Diagnostics.ProcessStartInfo startInfo, System.Threading.CancellationToken cancellationToken = default);
[<System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
static member RunAsync : System.Diagnostics.ProcessStartInfo * System.Threading.CancellationToken -> System.Threading.Tasks.Task<System.Diagnostics.ProcessExitStatus>
Public Shared Function RunAsync (startInfo As ProcessStartInfo, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ProcessExitStatus)
参数
- startInfo
- ProcessStartInfo
ProcessStartInfo包含用于启动进程的信息。
- cancellationToken
- CancellationToken
用于取消异步操作的令牌。 如果令牌已取消,则进程将终止。
返回
表示异步作的任务。 任务的值包含进程的退出状态。 如果由于取消而终止进程, Canceled 则为 true。
- 属性
例外
startInfo 是 null。
将 UseShellExecute 设置为 true。
- 或者 -
RedirectStandardInput、 RedirectStandardOutput或 RedirectStandardError 设置为 true。 请改用相应的标准句柄属性来提供句柄。
适用于
RunAsync(String, IEnumerable<String>, Boolean, CancellationToken)
- Source:
- Process.Scenarios.cs
异步启动具有指定文件名和可选参数的进程,等待其退出,并返回其退出状态。
[System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static System.Threading.Tasks.Task<System.Diagnostics.ProcessExitStatus> RunAsync(string fileName, System.Collections.Generic.IEnumerable<string>? arguments = default, bool silent = false, System.Threading.CancellationToken cancellationToken = default);
[<System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
static member RunAsync : string * seq<string> * bool * System.Threading.CancellationToken -> System.Threading.Tasks.Task<System.Diagnostics.ProcessExitStatus>
Public Shared Function RunAsync (fileName As String, Optional arguments As IEnumerable(Of String) = Nothing, Optional silent As Boolean = false, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ProcessExitStatus)
参数
- fileName
- String
要启动的可执行文件的名称。
- arguments
- IEnumerable<String>
要传递给进程的命令行参数。 传递 null 或空序列以启动进程,而无需其他参数。
- silent
- Boolean
当 true,将标准输入、输出和错误重定向到 null 设备时,确保进程不会生成可见的控制台输出。 当进程从父级继承标准句柄时 false。
- cancellationToken
- CancellationToken
用于取消异步操作的令牌。 如果令牌已取消,则进程将终止。
返回
表示异步作的任务。 任务的值包含进程的退出状态。 如果由于取消而终止进程, Canceled 则为 true。
- 属性
例外
fileName 是 null。
fileName 为空。