diff options
| author | stefan <stefan@hegedues.at> | 2018-09-12 19:26:21 +0200 |
|---|---|---|
| committer | stefan <stefan@hegedues.at> | 2018-09-12 19:26:21 +0200 |
| commit | 48facb797ed912e4ea6b04b17d1ff190ac2daac4 (patch) | |
| tree | 8dae77a31670a888d733484cb17dd4077d5444e8 /Emby.Server.Implementations/Diagnostics/CommonProcess.cs | |
| parent | c32d8656382a0eacb301692e0084377fc433ae9b (diff) | |
Update to 3.5.2 and .net core 2.1
Diffstat (limited to 'Emby.Server.Implementations/Diagnostics/CommonProcess.cs')
| -rw-r--r-- | Emby.Server.Implementations/Diagnostics/CommonProcess.cs | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/Emby.Server.Implementations/Diagnostics/CommonProcess.cs b/Emby.Server.Implementations/Diagnostics/CommonProcess.cs index a0a5f32ef..a709607bd 100644 --- a/Emby.Server.Implementations/Diagnostics/CommonProcess.cs +++ b/Emby.Server.Implementations/Diagnostics/CommonProcess.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.IO; using System.Threading.Tasks; using MediaBrowser.Model.Diagnostics; +using System.Threading; namespace Emby.Server.Implementations.Diagnostics { @@ -48,8 +49,32 @@ namespace Emby.Server.Implementations.Diagnostics } } + private bool _hasExited; + private bool HasExited + { + get + { + if (_hasExited) + { + return true; + } + + try + { + _hasExited = _process.HasExited; + } + catch (InvalidOperationException) + { + _hasExited = true; + } + + return _hasExited; + } + } + private void _process_Exited(object sender, EventArgs e) { + _hasExited = true; if (Exited != null) { Exited(this, e); @@ -98,13 +123,33 @@ namespace Emby.Server.Implementations.Diagnostics public Task<bool> WaitForExitAsync(int timeMs) { - return Task.FromResult(_process.WaitForExit(timeMs)); + //if (_process.WaitForExit(100)) + //{ + // return Task.FromResult(true); + //} + + //timeMs -= 100; + timeMs = Math.Max(0, timeMs); + + var tcs = new TaskCompletionSource<bool>(); + + var cancellationToken = new CancellationTokenSource(timeMs).Token; + + if (HasExited) + { + return Task.FromResult(true); + } + + _process.Exited += (sender, args) => tcs.TrySetResult(true); + + cancellationToken.Register(() => tcs.TrySetResult(HasExited)); + + return tcs.Task; } public void Dispose() { _process.Dispose(); - GC.SuppressFinalize(this); } } } |
