This repository has been archived on 2022-08-05. You can view files and clone it, but cannot push or open issues or pull requests.
testexetrisathlon/testexetrisathlon/SoundManagement/ProcessLoop.cs

33 lines
790 B
C#

using System.Diagnostics;
using System.Threading;
namespace testexetrisathlon.SoundManagement
{
internal class ProcessLoop
{
private readonly ProcessStartInfo _info;
private Process _currentProc;
private bool _isRunning = true;
public ProcessLoop(ProcessStartInfo info) => _info = info;
public bool IsRunning
{
set
{
if (_isRunning && !value)
_currentProc.Kill();
_isRunning = value;
}
}
public Thread CreateLoopThread() => new Thread(() =>
{
while (_isRunning)
{
_currentProc = Process.Start(_info);
_currentProc.WaitForExit();
}
});
}
}