Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

fix: Message以及 Notification 无法定时关闭的bug #200

Merged
merged 1 commit into from
Dec 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down