From 82bbf7052525329c7cc1ccbde307a34fa05bd7c4 Mon Sep 17 00:00:00 2001 From: TheXorog <56395159+TheXorog@users.noreply.github.com> Date: Sat, 14 May 2022 20:33:53 +0200 Subject: [PATCH] [FIX] Attempted fix for #1 --- Internal/Internal.cs | 2 +- UniversalExtensions.cs | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Internal/Internal.cs b/Internal/Internal.cs index 90d2b83..5461c80 100644 --- a/Internal/Internal.cs +++ b/Internal/Internal.cs @@ -88,7 +88,7 @@ internal static class Internal public class InternalSheduler { - public static Dictionary registeredScheduledTasks { get; private set; } = new Dictionary(); + public static Dictionary registeredScheduledTasks { get; internal set; } = new Dictionary(); public class taskInfo { diff --git a/UniversalExtensions.cs b/UniversalExtensions.cs index 72cefd6..9f3eff7 100644 --- a/UniversalExtensions.cs +++ b/UniversalExtensions.cs @@ -255,7 +255,22 @@ public static class UniversalExtensions task.Start(); }); - registeredScheduledTasks.Add(UID, new taskInfo { tokenSource = CancellationToken, customId = CustomId, runTime = runTime}); + if (registeredScheduledTasks is null) + registeredScheduledTasks = new(); + + try + { + registeredScheduledTasks.Add(UID, new taskInfo { tokenSource = CancellationToken, customId = CustomId, runTime = runTime }); + } + catch (InvalidOperationException) + { + registeredScheduledTasks = new(); + registeredScheduledTasks.Add(UID, new taskInfo { tokenSource = CancellationToken, customId = CustomId, runTime = runTime }); + } + catch (Exception) + { + throw; + } return UID; }