Last active
May 13, 2022 07:58
-
-
Save the9ball/dc8a245f7fca4263cab368f9e8a45739 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| dotnet script %~dp0hoge.csx 5 && echo success || echo error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (Args.Count < 1) | |
| { | |
| throw new ArgumentException("秒数を指定してください"); | |
| } | |
| var timeout = TimeSpan.FromSeconds(double.Parse(Args[0])); | |
| // プロセス起動 | |
| var p = System.Diagnostics.Process.Start("sleep.exe", "3"); | |
| try | |
| { | |
| var startTime = DateTime.UtcNow; | |
| while (!p.HasExited) | |
| { | |
| // なんかチェックする処理 | |
| await Task.Delay(TimeSpan.FromSeconds(1)); | |
| if (DateTime.UtcNow - startTime > timeout) | |
| { | |
| Console.WriteLine("Timeout"); | |
| p.Kill(); | |
| throw new TimeoutException(""); | |
| } | |
| } | |
| } | |
| finally | |
| { | |
| if (!p.HasExited) | |
| { | |
| p.Kill(); | |
| await p.WaitForExitAsync(); | |
| } | |
| } | |
| Console.WriteLine("Complete"); | |
| return p.ExitCode; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment