From 06b4df29cb0d822e7e2d6f5148ec82e229feb56a Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Wed, 15 May 2024 23:19:20 +0200 Subject: [PATCH] Exception handling https://github.com/seerge/g-helper/issues/2596 --- app/Helpers/Startup.cs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/app/Helpers/Startup.cs b/app/Helpers/Startup.cs index 38c9e9dc..41248fb9 100644 --- a/app/Helpers/Startup.cs +++ b/app/Helpers/Startup.cs @@ -30,15 +30,22 @@ public class Startup var task = taskService.RootFolder.AllTasks.FirstOrDefault(t => t.Name == taskName); if (task != null) { - string strExeFilePath = Application.ExecutablePath.Trim(); - string action = task.Definition.Actions.FirstOrDefault()!.ToString().Trim(); - if (!strExeFilePath.Equals(action, StringComparison.OrdinalIgnoreCase) && !File.Exists(action)) + try { - Logger.WriteLine("File doesn't exist: " + action); - Logger.WriteLine("Rescheduling to: " + strExeFilePath); - UnSchedule(); - Schedule(); + string strExeFilePath = Application.ExecutablePath.Trim(); + string action = task.Definition.Actions.FirstOrDefault()!.ToString().Trim(); + if (!strExeFilePath.Equals(action, StringComparison.OrdinalIgnoreCase) && !File.Exists(action)) + { + Logger.WriteLine("File doesn't exist: " + action); + Logger.WriteLine("Rescheduling to: " + strExeFilePath); + UnSchedule(); + Schedule(); + } + } catch (Exception ex) + { + Logger.WriteLine($"Can't check startup task: {ex.Message}"); } + } } }