diff --git a/Fairy.Engine.cs b/Fairy.Engine.cs index 113bcf4..48ee29c 100644 --- a/Fairy.Engine.cs +++ b/Fairy.Engine.cs @@ -296,7 +296,7 @@ internal void InitializeTimer() timer = new(OnTimer, null, settings.SessionExpirationTime.Milliseconds, 60000); } - internal void OnTimer(object state) + internal void OnTimer(object? state) { List<(string Id, FairySession Session)> toBeDestroyed = new(); foreach (var (id, session) in sessionStringToFairySession) diff --git a/Fairy.Utils.cs b/Fairy.Utils.cs index e64be64..ff47b03 100644 --- a/Fairy.Utils.cs +++ b/Fairy.Utils.cs @@ -83,19 +83,13 @@ protected virtual JToken AwaitConfirmedTransaction(JArray _params) { return json; } - uint count = 1; - bool expectBlockIn15Secs = false; - CommittedHandler getConfirmedTransactionAfterCommitted = delegate(NeoSystem @system, Block @block){ count += 1; expectBlockIn15Secs = true; json = GetConfirmedTransaction(hash, verbose); }; + SemaphoreSlim signal = new SemaphoreSlim(0, 1); + uint count = 0; + CommittedHandler getConfirmedTransactionAfterCommitted = delegate(NeoSystem @system, Block @block){ json = GetConfirmedTransaction(hash, verbose); count += 1; signal.Release(); }; Blockchain.Committed += getConfirmedTransactionAfterCommitted; - while (count <= waitBlockCount) + while (count < waitBlockCount) { - if (expectBlockIn15Secs == false) - Thread.Sleep(500); - else - { - expectBlockIn15Secs = false; - Thread.Sleep(14500); - } + signal.Wait(); if (json != null) { Blockchain.Committed -= getConfirmedTransactionAfterCommitted;