Process.RunAsync 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
多載
| 名稱 | Description |
|---|---|
| RunAsync(ProcessStartInfo, CancellationToken) |
非同步啟動由 描述 |
| RunAsync(String, IEnumerable<String>, Boolean, CancellationToken) |
非同步啟動一個以指定檔案名稱及可選參數的程序,等待其退出,並回傳其退出狀態。 |
RunAsync(ProcessStartInfo, CancellationToken)
非同步啟動由 描述 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)
非同步啟動一個以指定檔案名稱及可選參數的程序,等待其退出,並回傳其退出狀態。
[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時,會將標準輸入、輸出和錯誤導向到空裝置,確保程序不會產生可見的主控台輸出。 當 false時,程序繼承父程序的標準句柄。
- cancellationToken
- CancellationToken
一個取消非同步操作的標記。 若標記被取消,程序即終止。
傳回
一個代表非同步操作的任務。 任務的值包含程序的退出狀態。 若程序因取消而終止,則 Canceled 為 true。
- 屬性
例外狀況
fileName 是 null。
fileName 空無一人。