diff --git a/src/TDesign/Components/Notify/Abstractions/NotifyContainerComponentBase.cs b/src/TDesign/Components/Notify/Abstractions/NotifyContainerComponentBase.cs index b1b4428d..5c579b49 100644 --- a/src/TDesign/Components/Notify/Abstractions/NotifyContainerComponentBase.cs +++ b/src/TDesign/Components/Notify/Abstractions/NotifyContainerComponentBase.cs @@ -60,14 +60,27 @@ protected async Task AddItem(TConfiguration configuration) await OnTimeoutRemove(); - Task OnTimeoutRemove() + async Task OnTimeoutRemove() { - using Timer timer = new(async (state) => - { - await RemoveItem((TConfiguration)state); - }, configuration, configuration.Delay ??= Timeout.Infinite, Timeout.Infinite); - return Task.CompletedTask; +#if NET6_0_OR_GREATER + using PeriodicTimer timer = new(TimeSpan.FromMilliseconds(configuration.Delay ??= Timeout.Infinite)); + await timer.WaitForNextTickAsync(); + await RemoveItem(configuration); +#else + System.Timers.Timer timer = new(configuration.Delay?? Timeout.Infinite); + timer.Elapsed += (sender, args) => + { + if (sender is not System.Timers.Timer timer) + return; + + timer.Stop(); + timer.Dispose(); + RemoveItem(configuration); + }; + timer.Start(); + await Task.CompletedTask; +#endif } }