mirror of
https://github.com/SlothDpal/Relaunch-Process.git
synced 2026-02-22 17:27:38 +03:00
фикс исключения при попытке получить данные внезапно завершенного процесса.
This commit is contained in:
25
Form1.cs
25
Form1.cs
@@ -241,7 +241,7 @@ namespace Process_Auto_Relaunch
|
|||||||
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
|
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
|
||||||
{
|
{
|
||||||
Settings.Default.Save();
|
Settings.Default.Save();
|
||||||
Status("Наюлюдение отменено - приложение закрыто.", NotifyLevel.logAlways);
|
Status("Наблюдение отменено - приложение закрыто.", NotifyLevel.logAlways);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool ProcessByNameIsRuning(string name)
|
private bool ProcessByNameIsRuning(string name)
|
||||||
@@ -286,13 +286,26 @@ namespace Process_Auto_Relaunch
|
|||||||
{
|
{
|
||||||
if (ProcessByNameIsRuning(textBoxProcessName.Text))
|
if (ProcessByNameIsRuning(textBoxProcessName.Text))
|
||||||
{
|
{
|
||||||
|
double cpuTotalTime, cpuPercent;
|
||||||
|
string ProcessAnswer;
|
||||||
|
|
||||||
cpuMeasureTimer.Stop();
|
cpuMeasureTimer.Stop();
|
||||||
double cpuTotalTime = WatchedProcess.TotalProcessorTime.TotalMilliseconds - cpuLastTime;
|
try
|
||||||
cpuLastTime = WatchedProcess.TotalProcessorTime.TotalMilliseconds;
|
{
|
||||||
double cpuPercent = cpuTotalTime * 100 / (Environment.ProcessorCount * cpuMeasureTimer.ElapsedMilliseconds);
|
cpuTotalTime = WatchedProcess.TotalProcessorTime.TotalMilliseconds - cpuLastTime;
|
||||||
string ProcessAnswer = (WatchedProcess.Responding)?"Активен":"Неактивен";
|
cpuLastTime = WatchedProcess.TotalProcessorTime.TotalMilliseconds;
|
||||||
|
cpuPercent = cpuTotalTime * 100 / (Environment.ProcessorCount * cpuMeasureTimer.ElapsedMilliseconds);
|
||||||
|
ProcessAnswer = (WatchedProcess.Responding) ? "Активен" : "Неактивен";
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
cpuTotalTime = 0;
|
||||||
|
cpuPercent = 0;
|
||||||
|
ProcessAnswer = "Неактивен";
|
||||||
|
}
|
||||||
cpuMeasureTimer.Reset();
|
cpuMeasureTimer.Reset();
|
||||||
cpuMeasureTimer.Start();
|
cpuMeasureTimer.Start();
|
||||||
|
|
||||||
Status($"Процесс уже запущен.",NotifyLevel.logUpdateStatus);
|
Status($"Процесс уже запущен.",NotifyLevel.logUpdateStatus);
|
||||||
processInformationLabel.Text = $"Интерфейс: {ProcessAnswer}. ЦПУ: {cpuPercent:f2}% {cpuTotalTime:f2}мсек";
|
processInformationLabel.Text = $"Интерфейс: {ProcessAnswer}. ЦПУ: {cpuPercent:f2}% {cpuTotalTime:f2}мсек";
|
||||||
if (i < (int)numericUpDown1.Value) SendDiscordMessage($"Процесс {textBoxProcessName.Text} запущен.",NotifyLevel.logDiscord);
|
if (i < (int)numericUpDown1.Value) SendDiscordMessage($"Процесс {textBoxProcessName.Text} запущен.",NotifyLevel.logDiscord);
|
||||||
@@ -334,7 +347,7 @@ namespace Process_Auto_Relaunch
|
|||||||
}
|
}
|
||||||
else if (e.Error != null)
|
else if (e.Error != null)
|
||||||
{
|
{
|
||||||
Status("Произошла ошибка! Наблюдение остановлено.", NotifyLevel.logUpdateStatus | NotifyLevel.logDiscord);
|
Status("Произошла ошибка! Наблюдение остановлено. Error: " + e.Error.Message + " Stack trace: " + e.Error.StackTrace, NotifyLevel.logUpdateStatus | NotifyLevel.logDiscord | NotifyLevel.logHistory);
|
||||||
MessageBox.Show("Error: " + e.Error.Message + "/n" + e.Error.StackTrace, "Ошибка наблюдения", MessageBoxButtons.OK, MessageBoxIcon.Stop);
|
MessageBox.Show("Error: " + e.Error.Message + "/n" + e.Error.StackTrace, "Ошибка наблюдения", MessageBoxButtons.OK, MessageBoxIcon.Stop);
|
||||||
radioButtonDisableWathing.Checked = true;
|
radioButtonDisableWathing.Checked = true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user