2021-04-24 02:59:39 +02:00
|
|
|
|
/******************************************************************************/
|
|
|
|
|
/* SlunkCrypt, by LoRd_MuldeR <MuldeR2@GMX.de> */
|
|
|
|
|
/* This work has been released under the CC0 1.0 Universal license! */
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
using System;
|
2022-02-10 22:55:52 +01:00
|
|
|
|
using System.Collections.Concurrent;
|
2021-04-24 02:59:39 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.Specialized;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Threading;
|
|
|
|
|
|
|
|
|
|
namespace com.muldersoft.slunkcrypt.gui.utils
|
|
|
|
|
{
|
|
|
|
|
class ProcessRunner : IDisposable
|
|
|
|
|
{
|
|
|
|
|
public delegate void OutputLineHandler(string line, bool stream);
|
|
|
|
|
public delegate void ProgressChangedHandler(double progress);
|
|
|
|
|
public delegate bool ProgressStringHandler(string line, out double progress);
|
|
|
|
|
|
|
|
|
|
public event OutputLineHandler OutputAvailable;
|
|
|
|
|
public event ProgressChangedHandler ProgressChanged;
|
|
|
|
|
public const bool STDOUT = false, STDERR = true;
|
|
|
|
|
|
|
|
|
|
private readonly Process m_process = new Process();
|
|
|
|
|
private readonly Dispatcher m_dispatcher;
|
|
|
|
|
private readonly ProcessPriorityClass? m_priorityClass;
|
2022-02-11 22:02:50 +01:00
|
|
|
|
private readonly Task<int> m_hasExited;
|
2021-04-24 02:59:39 +02:00
|
|
|
|
|
2022-02-10 22:55:52 +01:00
|
|
|
|
private volatile bool m_running = false, m_finished = false, m_aborted = false, m_disposed = false;
|
2021-04-24 02:59:39 +02:00
|
|
|
|
|
|
|
|
|
// =============================================================================
|
|
|
|
|
// Exception classes
|
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
|
|
public class ProcessStartException : IOException
|
|
|
|
|
{
|
|
|
|
|
public ProcessStartException(string message, Exception innerException) : base(message, innerException)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class ProcessInterruptedException : IOException
|
|
|
|
|
{
|
|
|
|
|
public ProcessInterruptedException(string message) : base(message)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-11 22:02:50 +01:00
|
|
|
|
// =============================================================================
|
|
|
|
|
// Event handler class
|
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
|
|
private class ProcessExitHandler
|
|
|
|
|
{
|
|
|
|
|
private readonly TaskCompletionSource<int> completionSource = new TaskCompletionSource<int>();
|
|
|
|
|
|
|
|
|
|
public ProcessExitHandler(Process process)
|
|
|
|
|
{
|
|
|
|
|
if (ReferenceEquals(process, null))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("Process must not be null!");
|
|
|
|
|
}
|
|
|
|
|
process.Exited += OnProcessExit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<int> Task
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return completionSource.Task;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void OnProcessExit(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (sender is Process)
|
|
|
|
|
{
|
|
|
|
|
completionSource.TrySetResult(((Process)sender).ExitCode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-24 02:59:39 +02:00
|
|
|
|
// =============================================================================
|
|
|
|
|
// Constructor
|
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
|
|
public ProcessRunner(Dispatcher dispatcher, ProcessPriorityClass? priorityClass = null)
|
|
|
|
|
{
|
|
|
|
|
if (ReferenceEquals(m_dispatcher = dispatcher, null))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("Dispatcher must not be null!");
|
|
|
|
|
}
|
|
|
|
|
if ((m_priorityClass = priorityClass).HasValue && (!Enum.IsDefined(typeof(ProcessPriorityClass), priorityClass.Value)))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("The given ProcessPriorityClass is undefined!");
|
|
|
|
|
}
|
2022-02-11 22:02:50 +01:00
|
|
|
|
m_hasExited = InitializeProcess(m_process, true);
|
2021-04-24 02:59:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~ProcessRunner()
|
|
|
|
|
{
|
|
|
|
|
Dispose(); /*just to be sure*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// =============================================================================
|
|
|
|
|
// Public methods
|
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
|
|
public async Task<int> ExecAsnyc(string executablePath, string[] arguments = null, IReadOnlyDictionary<string, string> environmentVariables = null)
|
|
|
|
|
{
|
|
|
|
|
m_dispatcher.VerifyAccess();
|
|
|
|
|
if (m_disposed)
|
|
|
|
|
{
|
|
|
|
|
throw new ObjectDisposedException("ProcessRunner");
|
|
|
|
|
}
|
2022-02-10 22:55:52 +01:00
|
|
|
|
if (m_running || m_finished)
|
2021-04-24 02:59:39 +02:00
|
|
|
|
{
|
2022-02-10 22:55:52 +01:00
|
|
|
|
throw new InvalidOperationException("Process is still running or has already finished!");
|
2021-04-24 02:59:39 +02:00
|
|
|
|
}
|
|
|
|
|
m_running = true;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return await DoExecAsnyc(executablePath, arguments, environmentVariables);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
2022-02-10 22:55:52 +01:00
|
|
|
|
m_finished = true;
|
2021-04-24 02:59:39 +02:00
|
|
|
|
m_running = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-10 22:55:52 +01:00
|
|
|
|
public static async Task<Tuple<int, string[]>> ExecAsnyc(string executableFile, string[] arguments = null, IReadOnlyDictionary<string, string> environmentVariables = null, ProcessPriorityClass? priorityClass = null, TimeSpan? timeout = null)
|
|
|
|
|
{
|
2022-02-11 22:02:50 +01:00
|
|
|
|
|
2022-02-10 22:55:52 +01:00
|
|
|
|
using (Process process = new Process())
|
|
|
|
|
{
|
2022-02-11 22:02:50 +01:00
|
|
|
|
Task<int> hasExitedTask = InitializeProcess(process);
|
|
|
|
|
return await DoExecAsnyc(process, hasExitedTask, executableFile, arguments, environmentVariables, priorityClass, timeout);
|
2022-02-10 22:55:52 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-24 02:59:39 +02:00
|
|
|
|
public void AbortProcess()
|
|
|
|
|
{
|
|
|
|
|
if ((!m_disposed) && m_running)
|
|
|
|
|
{
|
|
|
|
|
m_aborted = true;
|
|
|
|
|
KillProcess();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void Dispose()
|
|
|
|
|
{
|
|
|
|
|
if (!m_disposed)
|
|
|
|
|
{
|
|
|
|
|
m_disposed = true;
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
KillProcess();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
m_process.Dispose();
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// =============================================================================
|
|
|
|
|
// Protected methods
|
|
|
|
|
// =============================================================================
|
|
|
|
|
|
2022-02-10 22:55:52 +01:00
|
|
|
|
protected virtual double ParseProgressString(ref string currentLine, bool stream)
|
2021-04-24 02:59:39 +02:00
|
|
|
|
{
|
|
|
|
|
return double.NaN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// =============================================================================
|
2022-02-10 22:55:52 +01:00
|
|
|
|
// Internal methods
|
2021-04-24 02:59:39 +02:00
|
|
|
|
// =============================================================================
|
|
|
|
|
|
2022-02-11 22:02:50 +01:00
|
|
|
|
private static Task<int> InitializeProcess(Process process, bool redirStdErr = false)
|
2021-04-24 02:59:39 +02:00
|
|
|
|
{
|
2022-02-10 22:55:52 +01:00
|
|
|
|
process.StartInfo.UseShellExecute = false;
|
|
|
|
|
process.StartInfo.CreateNoWindow = true;
|
|
|
|
|
process.StartInfo.RedirectStandardOutput = true;
|
|
|
|
|
process.StartInfo.StandardOutputEncoding = Encoding.UTF8;
|
|
|
|
|
if (redirStdErr)
|
2021-04-24 02:59:39 +02:00
|
|
|
|
{
|
2022-02-10 22:55:52 +01:00
|
|
|
|
process.StartInfo.RedirectStandardError = true;
|
|
|
|
|
process.StartInfo.StandardErrorEncoding = Encoding.UTF8;
|
|
|
|
|
}
|
2022-02-11 22:02:50 +01:00
|
|
|
|
process.EnableRaisingEvents = true;
|
|
|
|
|
return new ProcessExitHandler(process).Task;
|
2021-04-24 02:59:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task<int> DoExecAsnyc(string executablePath, string[] arguments, IReadOnlyDictionary<string, string> environmentVariables)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2022-02-10 22:55:52 +01:00
|
|
|
|
StartProcess(m_process, executablePath, arguments, environmentVariables, m_priorityClass);
|
2021-04-24 02:59:39 +02:00
|
|
|
|
}
|
|
|
|
|
catch (Exception err)
|
|
|
|
|
{
|
|
|
|
|
throw new ProcessStartException("Failed to create the process!", err);
|
|
|
|
|
}
|
|
|
|
|
return await WaitForExit();
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-10 22:55:52 +01:00
|
|
|
|
private static async Task<Tuple<int,string[]>> DoExecAsnyc(Process process, Task<int> hasExited, string executablePath, string[] arguments, IReadOnlyDictionary<string, string> environmentVariables, ProcessPriorityClass? priorityClass, TimeSpan? timeout)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
StartProcess(process, executablePath, arguments, environmentVariables, priorityClass);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception err)
|
|
|
|
|
{
|
|
|
|
|
throw new ProcessStartException("Failed to create the process!", err);
|
|
|
|
|
}
|
|
|
|
|
string[] outputLines = await WaitForExit(process, hasExited, timeout.GetValueOrDefault(TimeSpan.MaxValue));
|
|
|
|
|
return Tuple.Create(hasExited.Result, outputLines);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void StartProcess(Process process, string executablePath, string[] arguments, IReadOnlyDictionary<string, string> environmentVariables, ProcessPriorityClass? priorityClass)
|
2021-04-24 02:59:39 +02:00
|
|
|
|
{
|
2022-02-10 22:55:52 +01:00
|
|
|
|
process.StartInfo.FileName = executablePath;
|
|
|
|
|
process.StartInfo.Arguments = CreateArgumentList(arguments);
|
2022-04-03 14:58:59 +02:00
|
|
|
|
SetupEnvironment(process.StartInfo.EnvironmentVariables, executablePath, environmentVariables);
|
2022-02-10 22:55:52 +01:00
|
|
|
|
process.StartInfo.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory;
|
|
|
|
|
process.Start();
|
|
|
|
|
SetProcessPriority(process, priorityClass);
|
2021-04-24 02:59:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task<int> WaitForExit()
|
|
|
|
|
{
|
2022-02-10 22:55:52 +01:00
|
|
|
|
Task readStdOutTask = Task.Run(() => ReadProcessOutput(m_process.StandardOutput, (line) => HandleOutput(line, STDOUT)));
|
|
|
|
|
Task readStdErrTask = Task.Run(() => ReadProcessOutput(m_process.StandardError, (line) => HandleOutput(line, STDERR)));
|
2022-02-11 22:02:50 +01:00
|
|
|
|
await Task.WhenAll(readStdOutTask, readStdErrTask, m_hasExited);
|
2021-04-24 02:59:39 +02:00
|
|
|
|
if (m_aborted || m_disposed)
|
|
|
|
|
{
|
|
|
|
|
NotifyOutputAvailable("\u2192 Process has been aborted !!!", true);
|
|
|
|
|
throw new ProcessInterruptedException("Process has been aborted!");
|
|
|
|
|
}
|
2022-02-11 22:02:50 +01:00
|
|
|
|
int processExitCode = m_hasExited.Result;
|
|
|
|
|
NotifyOutputAvailable(string.Format("\u2192 Process terminated normally [Exit status: {0:D}]", processExitCode), false);
|
|
|
|
|
return processExitCode;
|
2021-04-24 02:59:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-10 22:55:52 +01:00
|
|
|
|
private static async Task<string[]> WaitForExit(Process process, Task<int> hasExited, TimeSpan timeout)
|
2021-04-24 02:59:39 +02:00
|
|
|
|
{
|
2022-02-10 22:55:52 +01:00
|
|
|
|
ConcurrentStack<string> outputLines = new ConcurrentStack<string>();
|
|
|
|
|
Task readerTask = Task.Run(() => ReadProcessOutput(process.StandardOutput, (line) => outputLines.Push(line)));
|
|
|
|
|
if (await Task.WhenAny(hasExited, Task.Delay(timeout)) != hasExited)
|
|
|
|
|
{
|
|
|
|
|
KillProcess(process);
|
|
|
|
|
}
|
|
|
|
|
await Task.WhenAll(readerTask, hasExited);
|
|
|
|
|
return outputLines.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void ReadProcessOutput(StreamReader reader, Action<string> outputHandler)
|
|
|
|
|
{
|
|
|
|
|
using (reader)
|
2021-04-24 02:59:39 +02:00
|
|
|
|
{
|
|
|
|
|
char[] buffer = new char[1024];
|
2022-02-10 22:55:52 +01:00
|
|
|
|
StringBuilder lineBuffer = new StringBuilder();
|
2021-04-24 02:59:39 +02:00
|
|
|
|
while (!reader.EndOfStream)
|
|
|
|
|
{
|
2022-02-10 22:55:52 +01:00
|
|
|
|
ReadNextChunk(reader, buffer, lineBuffer, outputHandler);
|
2021-04-24 02:59:39 +02:00
|
|
|
|
}
|
2022-02-10 22:55:52 +01:00
|
|
|
|
ProcessLine(lineBuffer, outputHandler);
|
2021-04-24 02:59:39 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-10 22:55:52 +01:00
|
|
|
|
private static void ReadNextChunk(StreamReader reader, char[] buffer, StringBuilder lineBuffer, Action<string> outputHandler)
|
2021-04-24 02:59:39 +02:00
|
|
|
|
{
|
|
|
|
|
int count = reader.Read(buffer, 0, buffer.Length);
|
|
|
|
|
if (count > 0)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < count; ++i)
|
|
|
|
|
{
|
|
|
|
|
char c = buffer[i];
|
|
|
|
|
if ((c != '\0') && (c != '\n') && (c != '\r') && (c != '\b'))
|
|
|
|
|
{
|
2022-02-10 22:55:52 +01:00
|
|
|
|
lineBuffer.Append(c);
|
2021-04-24 02:59:39 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-02-10 22:55:52 +01:00
|
|
|
|
ProcessLine(lineBuffer, outputHandler);
|
|
|
|
|
lineBuffer.Clear();
|
2021-04-24 02:59:39 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-10 22:55:52 +01:00
|
|
|
|
private static void ProcessLine(StringBuilder lineBuffer, Action<string> outputHandler)
|
2021-04-24 02:59:39 +02:00
|
|
|
|
{
|
2022-02-10 22:55:52 +01:00
|
|
|
|
if (lineBuffer.Length > 0)
|
2021-04-24 02:59:39 +02:00
|
|
|
|
{
|
2022-02-10 22:55:52 +01:00
|
|
|
|
String currentLine;
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(currentLine = lineBuffer.ToString()))
|
2021-04-24 02:59:39 +02:00
|
|
|
|
{
|
2022-02-10 22:55:52 +01:00
|
|
|
|
outputHandler.Invoke(currentLine.Trim());
|
2021-04-24 02:59:39 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-10 22:55:52 +01:00
|
|
|
|
private void HandleOutput(string currentLine, bool stream)
|
2021-04-24 02:59:39 +02:00
|
|
|
|
{
|
2022-02-10 22:55:52 +01:00
|
|
|
|
CheckForProgressUpdate(ref currentLine, stream);
|
|
|
|
|
if (!String.IsNullOrEmpty(currentLine))
|
2021-04-24 02:59:39 +02:00
|
|
|
|
{
|
2022-02-10 22:55:52 +01:00
|
|
|
|
NotifyOutputAvailable(currentLine, stream);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CheckForProgressUpdate(ref string currentLine, bool stream)
|
|
|
|
|
{
|
|
|
|
|
double progress = ParseProgressString(ref currentLine, stream);
|
|
|
|
|
if (!double.IsNaN(progress))
|
|
|
|
|
{
|
|
|
|
|
NotifyProgressChanged(progress);
|
2021-04-24 02:59:39 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void NotifyOutputAvailable(string line, bool stream)
|
|
|
|
|
{
|
|
|
|
|
if (!ReferenceEquals(OutputAvailable, null))
|
|
|
|
|
{
|
|
|
|
|
m_dispatcher.InvokeAsync(() => OutputAvailable(line, stream));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void NotifyProgressChanged(double progress)
|
|
|
|
|
{
|
|
|
|
|
if (!ReferenceEquals(ProgressChanged, null))
|
|
|
|
|
{
|
|
|
|
|
m_dispatcher.InvokeAsync(() => ProgressChanged(Math.Max(0.0, Math.Min(1.0, progress))));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string CreateArgumentList(string[] arguments)
|
|
|
|
|
{
|
|
|
|
|
StringBuilder argumentList = new StringBuilder();
|
|
|
|
|
if (!ReferenceEquals(arguments, null))
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < arguments.Length; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (i > 0)
|
|
|
|
|
{
|
|
|
|
|
argumentList.Append("\x20");
|
|
|
|
|
}
|
|
|
|
|
argumentList.Append(EscapeArgument(arguments[i]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return argumentList.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string EscapeArgument(string str)
|
|
|
|
|
{
|
|
|
|
|
if (RequiresQuotation(str))
|
|
|
|
|
{
|
|
|
|
|
StringBuilder sb = new StringBuilder().Append('"');
|
|
|
|
|
foreach (char c in str)
|
|
|
|
|
{
|
|
|
|
|
if (c == '"')
|
|
|
|
|
{
|
|
|
|
|
sb.Append('\\').Append('"');
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sb.Append(c);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return sb.Append('"').ToString();
|
|
|
|
|
}
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static bool RequiresQuotation(string str)
|
|
|
|
|
{
|
|
|
|
|
foreach (char c in str)
|
|
|
|
|
{
|
|
|
|
|
if (char.IsWhiteSpace(c) || (c == '"'))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-03 14:58:59 +02:00
|
|
|
|
private static void SetupEnvironment(StringDictionary dictionary, string executablePath, IReadOnlyDictionary<string, string> environmentVariables)
|
2021-04-24 02:59:39 +02:00
|
|
|
|
{
|
2022-04-03 14:58:59 +02:00
|
|
|
|
string baseDirectory = Path.GetDirectoryName(executablePath);
|
|
|
|
|
dictionary["PATH"] = string.IsNullOrEmpty(baseDirectory) ? Environment.SystemDirectory : baseDirectory;
|
2021-04-24 02:59:39 +02:00
|
|
|
|
if (!ReferenceEquals(environmentVariables, null))
|
|
|
|
|
{
|
|
|
|
|
foreach (KeyValuePair<string, string> entry in environmentVariables)
|
|
|
|
|
{
|
2022-04-03 14:58:59 +02:00
|
|
|
|
dictionary[entry.Key] = entry.Value;
|
2021-04-24 02:59:39 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void KillProcess()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
m_process.Kill();
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-10 22:55:52 +01:00
|
|
|
|
private static void KillProcess(Process process)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
process.Kill();
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void SetProcessPriority(Process process, ProcessPriorityClass? priorityClass)
|
2021-04-24 02:59:39 +02:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (priorityClass.HasValue)
|
|
|
|
|
{
|
2022-02-10 22:55:52 +01:00
|
|
|
|
process.PriorityClass = priorityClass.Value;
|
2021-04-24 02:59:39 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|