1
我需要執行commandpromt進程異步並獲取執行的輸出。我目前有這個代碼執行命令提示進程asnyc並得到結果
Public Function ExecuteCommandSync(ByVal command As Object) As String
Dim result As String = Nothing
Try
Dim procStartInfo As New System.Diagnostics.ProcessStartInfo("cmd", "/c " & Convert.ToString(command))
procStartInfo.RedirectStandardOutput = True
procStartInfo.UseShellExecute = False
procStartInfo.CreateNoWindow = True
Dim proc As New System.Diagnostics.Process()
proc.StartInfo = procStartInfo
proc.Start()
result = proc.StandardOutput.ReadToEnd()
Console.WriteLine(result)
Catch objException As Exception
End Try
Return result
End Function
請幫助我將其轉換爲async,而不使用線程。這可能嗎?
謝謝