File tree Expand file tree Collapse file tree
Common.BasicHelper/Core/Shell Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ public static async Task<string> GetExecutionResultAsync
6767 string args ,
6868 bool findInPath = false ,
6969 Action < ProcessStartInfo > ? action = null ,
70- CancellationToken ? token = default
70+ CancellationToken ? token = null
7171 )
7272 {
7373 if ( findInPath )
@@ -90,19 +90,24 @@ public static async Task<string> GetExecutionResultAsync
9090 StartInfo = psi ,
9191 } ;
9292
93- //var sb = new StringBuilder();
94-
95- //void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
96- // => sb.AppendLine(outLine.Data);
97-
98- //process.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);
99- //process.ErrorDataReceived += new DataReceivedEventHandler(OutputHandler);
100-
10193 process . Start ( ) ;
10294
10395 var output = process . StandardOutput . ReadToEnd ( ) ;
10496
105- await Task . Run ( process . WaitForExit ) ;
97+ await Task . Run ( ( ) =>
98+ {
99+ if ( token is null ) process . WaitForExit ( ) ;
100+
101+ while ( ! process . HasExited )
102+ {
103+ if ( token is not null && token . Value . IsCancellationRequested )
104+ {
105+ process . Kill ( ) ;
106+
107+ break ;
108+ }
109+ }
110+ } ) ;
106111
107112 return output ;
108113 }
You can’t perform that action at this time.
0 commit comments