Skip to content

Commit

Permalink
Major Bug Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MistressPlague authored Jun 11, 2021
1 parent 239667a commit 57ca3b7
Showing 1 changed file with 53 additions and 7 deletions.
60 changes: 53 additions & 7 deletions Auto Restart Process/Auto Restart Process/Auto Restart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class Configuration
{
public bool IsAutoRestarting
{
get => Instance.checkBox1.Checked;
get => Instance != null && Instance.checkBox1.Checked;
set
{
try
Expand Down Expand Up @@ -153,6 +153,38 @@ public Point Pos
}
}
}

public bool KillIfNotResponding
{
get => Instance.NotRespondingPref.Checked;
set
{
try
{
Instance.NotRespondingPref.Checked = value;
}
catch
{

}
}
}

public decimal NotRespondingTime
{
get => Instance.numericUpDown2.Value;
set
{
try
{
Instance.numericUpDown2.Value = value;
}
catch
{

}
}
}
}

public static bool IsAdmin = false;
Expand Down Expand Up @@ -267,7 +299,14 @@ private void checkBox2_CheckedChanged(object sender, EventArgs e)
// ReSharper disable once MethodNameNotMeaningful
public void Log(string text)
{
LogBox.AppendText("[" + DateTime.Now.ToString("hh:MM:ss tt") + "] " + text + "\r\n");
try
{
LogBox.AppendText("[" + DateTime.Now.ToString("hh:MM:ss tt") + "] " + text + "\r\n");
}
catch
{

}
}

private Stopwatch TimePassed = new Stopwatch();
Expand Down Expand Up @@ -320,17 +359,16 @@ private void RestartWorker_DoWork(object sender, System.ComponentModel.DoWorkEve
Log("Process Started!");

AlreadyStarted:
var HungTooLong = false;

while (Proc != null && !Proc.HasExited && !HungTooLong)
while (Proc != null && !Proc.HasExited)
{
if (HungTimePassed.ElapsedMilliseconds >= numericUpDown2.Value)
{
HungTooLong = true;
HungTimePassed.Reset();
Proc.Kill();
break;
}

if (!Proc.Responding)
if (!Proc.HasExited && !Proc.Responding)
{
HungTimePassed.Start();
}
Expand Down Expand Up @@ -398,5 +436,13 @@ private void AutoRestartForm_LocationChanged(object sender, EventArgs e)
JsonConfig.SaveConfig(Config);
}
}

private void numericUpDown2_ValueChanged(object sender, EventArgs e)
{
if (HasInit)
{
JsonConfig.SaveConfig(Config);
}
}
}
}

0 comments on commit 57ca3b7

Please sign in to comment.