mirror of
https://github.com/Stone-Red-Code/RemSox.git
synced 2026-09-04 00:56:19 +02:00
Add process exception handling and clean window closing logic
This commit is contained in:
@@ -69,7 +69,7 @@ public class DesktopProcess : Process
|
|||||||
WindowManager.Update();
|
WindowManager.Update();
|
||||||
|
|
||||||
// Sleep slightly to yield CPU to the main CLI thread (approx 60 FPS)
|
// Sleep slightly to yield CPU to the main CLI thread (approx 60 FPS)
|
||||||
//Thread.Sleep(16);
|
Thread.Sleep(16);
|
||||||
}
|
}
|
||||||
|
|
||||||
IsRunning = false;
|
IsRunning = false;
|
||||||
|
|||||||
@@ -140,14 +140,13 @@ public class TerminalProcess : Process
|
|||||||
// The last line is the input line
|
// The last line is the input line
|
||||||
textLines[maxLines].Content = "> " + currentInput + "_";
|
textLines[maxLines].Content = "> " + currentInput + "_";
|
||||||
textLines[maxLines].Position = new Point(5, startY + (maxLines * LineHeight));
|
textLines[maxLines].Position = new Point(5, startY + (maxLines * LineHeight));
|
||||||
|
|
||||||
// Hide any extra text lines we don't need
|
// Hide any extra text lines we don't need
|
||||||
for (int i = maxLines + 1; i < textLines.Count; i++)
|
for (int i = maxLines + 1; i < textLines.Count; i++)
|
||||||
{
|
{
|
||||||
textLines[i].Content = "";
|
textLines[i].Content = "";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
window.Flush();
|
window.Flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
using RemSox.UI.GUI.Windows;
|
||||||
|
|
||||||
namespace RemSox.Processing;
|
namespace RemSox.Processing;
|
||||||
|
|
||||||
@@ -18,7 +19,22 @@ public static class ProcessManager
|
|||||||
Id = id
|
Id = id
|
||||||
};
|
};
|
||||||
|
|
||||||
Thread thread = new(process.Run);
|
Thread thread = new(() =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
process.Run();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Process {process.Name} (ID: {process.Id}) terminated with an exception: {ex}");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
processes.TryRemove(id, out _);
|
||||||
|
WindowManager.CloseWindowsForProcess(id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
processes.TryAdd(id, (process, thread));
|
processes.TryAdd(id, (process, thread));
|
||||||
|
|
||||||
@@ -34,6 +50,8 @@ public static class ProcessManager
|
|||||||
|
|
||||||
entry.Process.RequestStop();
|
entry.Process.RequestStop();
|
||||||
|
|
||||||
|
WindowManager.CloseWindowsForProcess(processId);
|
||||||
|
|
||||||
processes.TryRemove(processId, out _);
|
processes.TryRemove(processId, out _);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +59,7 @@ public static class ProcessManager
|
|||||||
{
|
{
|
||||||
foreach (var entry in processes.Values)
|
foreach (var entry in processes.Values)
|
||||||
{
|
{
|
||||||
entry.Process.RequestStop();
|
StopProcess(entry.Process.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
processes.Clear();
|
processes.Clear();
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public static class WindowManager
|
|||||||
|
|
||||||
wasLeftButtonDown = leftButtonDown;
|
wasLeftButtonDown = leftButtonDown;
|
||||||
|
|
||||||
if (KeyboardManager.TryReadKey(out KeyEvent keyEvent))
|
while (KeyboardManager.TryReadKey(out KeyEvent keyEvent))
|
||||||
{
|
{
|
||||||
focusedWindow?.HandleKeyEvent(keyEvent);
|
focusedWindow?.HandleKeyEvent(keyEvent);
|
||||||
}
|
}
|
||||||
@@ -117,10 +117,15 @@ public static class WindowManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void CloseWindowsForProcess(Process process)
|
public static void CloseWindowsForProcess(Process process)
|
||||||
|
{
|
||||||
|
CloseWindowsForProcess(process.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void CloseWindowsForProcess(int processId)
|
||||||
{
|
{
|
||||||
lock (windowsLock)
|
lock (windowsLock)
|
||||||
{
|
{
|
||||||
windows.Remove(process.Id);
|
windows.Remove(processId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user