revert of process limit (for now)

This commit is contained in:
pointfeev 2022-02-10 20:33:28 -05:00
parent b1a528799b
commit d8fcc1a88c

View file

@ -6,7 +6,6 @@ using System.IO.Compression;
using System.Linq; using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
@ -29,43 +28,43 @@ internal static class SteamCMD
internal static readonly Version MinimumAppInfoVersion = Version.Parse("2.0.3.2"); internal static readonly Version MinimumAppInfoVersion = Version.Parse("2.0.3.2");
internal static readonly string AppInfoVersionPath = AppInfoPath + @"\version.txt"; internal static readonly string AppInfoVersionPath = AppInfoPath + @"\version.txt";
private static readonly int[] locks = new int[20]; // acts as an effective process limit //private static readonly int[] locks = new int[20]; // acts as an effective process limit
internal static async Task<string> Run(string command) => await Task.Run(() => internal static async Task<string> Run(string command) => await Task.Run(() =>
{ {
wait_for_lock: /*wait_for_lock:
if (Program.Canceled) return "";
for (int i = 0; i < locks.Length; i++)
{
if (Program.Canceled) return ""; if (Program.Canceled) return "";
if (Interlocked.CompareExchange(ref locks[i], 1, 0) == 0) for (int i = 0; i < locks.Length; i++)
{ {
if (Program.Canceled) return ""; if (Program.Canceled) return "";
List<string> logs = new(); if (Interlocked.CompareExchange(ref locks[i], 1, 0) == 0)
ProcessStartInfo processStartInfo = new() {*/
{ if (Program.Canceled) return "";
FileName = FilePath, List<string> logs = new();
RedirectStandardOutput = true, ProcessStartInfo processStartInfo = new()
RedirectStandardInput = true, {
RedirectStandardError = true, FileName = FilePath,
UseShellExecute = false, RedirectStandardOutput = true,
Arguments = command, RedirectStandardInput = true,
CreateNoWindow = true, RedirectStandardError = true,
StandardInputEncoding = Encoding.UTF8, UseShellExecute = false,
StandardOutputEncoding = Encoding.UTF8, Arguments = command,
StandardErrorEncoding = Encoding.UTF8 CreateNoWindow = true,
}; StandardInputEncoding = Encoding.UTF8,
using Process process = Process.Start(processStartInfo); StandardOutputEncoding = Encoding.UTF8,
process.OutputDataReceived += (object sender, DataReceivedEventArgs e) => logs.Add(e.Data); StandardErrorEncoding = Encoding.UTF8
process.BeginOutputReadLine(); };
process.ErrorDataReceived += (object sender, DataReceivedEventArgs e) => logs.Add(e.Data); using Process process = Process.Start(processStartInfo);
process.BeginErrorReadLine(); process.OutputDataReceived += (object sender, DataReceivedEventArgs e) => logs.Add(e.Data);
process.WaitForExit(); process.BeginOutputReadLine();
Interlocked.Decrement(ref locks[i]); process.ErrorDataReceived += (object sender, DataReceivedEventArgs e) => logs.Add(e.Data);
return string.Join("\r\n", logs); process.BeginErrorReadLine();
} process.WaitForExit();
Thread.Sleep(0); //Interlocked.Decrement(ref locks[i]);
} return string.Join("\r\n", logs);
goto wait_for_lock; /*}
Thread.Sleep(200);
}
goto wait_for_lock;*/
}); });
internal static async Task Setup(IProgress<int> progress = null) internal static async Task Setup(IProgress<int> progress = null)