aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Diagnostics/CommonProcess.cs
diff options
context:
space:
mode:
authorLogicalPhallacy <44458166+LogicalPhallacy@users.noreply.github.com>2019-03-16 00:25:16 -0700
committerGitHub <noreply@github.com>2019-03-16 00:25:16 -0700
commit2d0844b5dbf08869896c5479c10675c4fe7fa988 (patch)
treedea28b14d2b1733edf1a90a46f4163f6123616fe /Emby.Server.Implementations/Diagnostics/CommonProcess.cs
parent221389089cc9ca4b69907d6bf3e9d38bf94393ea (diff)
parent59031ee3b8b2ac8298c41f9171b658e3f15e17bc (diff)
Merge pull request #1 from jellyfin/master
merging myself to latest
Diffstat (limited to 'Emby.Server.Implementations/Diagnostics/CommonProcess.cs')
-rw-r--r--Emby.Server.Implementations/Diagnostics/CommonProcess.cs72
1 files changed, 43 insertions, 29 deletions
diff --git a/Emby.Server.Implementations/Diagnostics/CommonProcess.cs b/Emby.Server.Implementations/Diagnostics/CommonProcess.cs
index 2c4ef170d..175a8f3ce 100644
--- a/Emby.Server.Implementations/Diagnostics/CommonProcess.cs
+++ b/Emby.Server.Implementations/Diagnostics/CommonProcess.cs
@@ -9,14 +9,14 @@ namespace Emby.Server.Implementations.Diagnostics
{
public class CommonProcess : IProcess
{
- public event EventHandler Exited;
-
- private readonly ProcessOptions _options;
private readonly Process _process;
+ private bool _disposed = false;
+ private bool _hasExited;
+
public CommonProcess(ProcessOptions options)
{
- _options = options;
+ StartInfo = options;
var startInfo = new ProcessStartInfo
{
@@ -27,10 +27,10 @@ namespace Emby.Server.Implementations.Diagnostics
CreateNoWindow = options.CreateNoWindow,
RedirectStandardError = options.RedirectStandardError,
RedirectStandardInput = options.RedirectStandardInput,
- RedirectStandardOutput = options.RedirectStandardOutput
+ RedirectStandardOutput = options.RedirectStandardOutput,
+ ErrorDialog = options.ErrorDialog
};
- startInfo.ErrorDialog = options.ErrorDialog;
if (options.IsHidden)
{
@@ -45,11 +45,22 @@ namespace Emby.Server.Implementations.Diagnostics
if (options.EnableRaisingEvents)
{
_process.EnableRaisingEvents = true;
- _process.Exited += _process_Exited;
+ _process.Exited += OnProcessExited;
}
}
- private bool _hasExited;
+ public event EventHandler Exited;
+
+ public ProcessOptions StartInfo { get; }
+
+ public StreamWriter StandardInput => _process.StandardInput;
+
+ public StreamReader StandardError => _process.StandardError;
+
+ public StreamReader StandardOutput => _process.StandardOutput;
+
+ public int ExitCode => _process.ExitCode;
+
private bool HasExited
{
get
@@ -72,25 +83,6 @@ namespace Emby.Server.Implementations.Diagnostics
}
}
- private void _process_Exited(object sender, EventArgs e)
- {
- _hasExited = true;
- if (Exited != null)
- {
- Exited(this, e);
- }
- }
-
- public ProcessOptions StartInfo => _options;
-
- public StreamWriter StandardInput => _process.StandardInput;
-
- public StreamReader StandardError => _process.StandardError;
-
- public StreamReader StandardOutput => _process.StandardOutput;
-
- public int ExitCode => _process.ExitCode;
-
public void Start()
{
_process.Start();
@@ -108,7 +100,7 @@ namespace Emby.Server.Implementations.Diagnostics
public Task<bool> WaitForExitAsync(int timeMs)
{
- //Note: For this function to work correctly, the option EnableRisingEvents needs to be set to true.
+ // Note: For this function to work correctly, the option EnableRisingEvents needs to be set to true.
if (HasExited)
{
@@ -130,7 +122,29 @@ namespace Emby.Server.Implementations.Diagnostics
public void Dispose()
{
- _process?.Dispose();
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ protected virtual void Dispose(bool disposing)
+ {
+ if (_disposed)
+ {
+ return;
+ }
+
+ if (disposing)
+ {
+ _process?.Dispose();
+ }
+
+ _disposed = true;
+ }
+
+ private void OnProcessExited(object sender, EventArgs e)
+ {
+ _hasExited = true;
+ Exited?.Invoke(this, e);
}
}
}