jsakamoto / Toolbelt.Blazor.HotKeys2

This is a class library that provides configuration-centric keyboard shortcuts for your Blazor apps.
https://jsakamoto.github.io/Toolbelt.Blazor.HotKeys2/
Mozilla Public License 2.0
87 stars 6 forks source link

Disposing immediately after "CreateContext" will not work. #20

Closed TFujisawa123 closed 2 months ago

TFujisawa123 commented 2 months ago

The code below does not dispose "HotKeysContext". Even after Dispose, the "G" key hotkey remains valid and cannot be deleted.

this.HotKeysContext = this.HotKeys.CreateContext().Add(Code.G, OnHotKey);
for (int i = 0; i < 100; i++)
{
    // something process
}
this.HotKeysContext?.Dispose();

Inserting "Task.Delay(1)" will dispose successfully.

this.HotKeysContext = this.HotKeys.CreateContext().Add(Code.G, OnHotKey);
for (int i = 0; i < 100; i++)
{
    // something process
}
await Task.Delay(1);
this.HotKeysContext?.Dispose();
jsakamoto commented 2 months ago

Hello @TFujisawa123, Thank you for letting me know that bug! I fixed it and published a new version today.

Could you try it out? Again, thank you for your contributions!

TFujisawa123 commented 2 months ago

Thanks that update. It worked as expected.