From af2925287d8c8523fc3ad9ac8075243b379bcd7c Mon Sep 17 00:00:00 2001 From: RaidMax Date: Wed, 5 Apr 2023 22:26:42 -0500 Subject: [PATCH] Add NotifyAfterDelay helper method --- SharedLibraryCore/Utilities.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/SharedLibraryCore/Utilities.cs b/SharedLibraryCore/Utilities.cs index f0ceafa62..57ebd7243 100644 --- a/SharedLibraryCore/Utilities.cs +++ b/SharedLibraryCore/Utilities.cs @@ -1331,5 +1331,24 @@ namespace SharedLibraryCore return serviceCollection; } + + public static void NotifyAfterDelay(TimeSpan duration, Func action) => + NotifyAfterDelay((int)duration.TotalMilliseconds, action); + + public static void NotifyAfterDelay(int delayMs, Func action) + { + Task.Run(async () => + { + try + { + await Task.Delay(delayMs); + await action(); + } + catch + { + // ignored + } + }); + } } }