Skip to content

Commit

Permalink
fix to dispose the disposable field object
Browse files Browse the repository at this point in the history
  • Loading branch information
smdn committed Apr 3, 2024
1 parent 01020a2 commit c1d4c45
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ partial class EchonetClient
/// ECHONET Lite フレームのリクエスト送信時の排他区間を定義するセマフォ。
/// <see cref="requestFrameBuffer"/>への書き込み、および<see cref="echonetLiteHandler"/>による送信を排他制御するために使用する。
/// </summary>
private readonly SemaphoreSlim requestSemaphore = new(initialCount: 1, maxCount: 1);
private SemaphoreSlim requestSemaphore = new(initialCount: 1, maxCount: 1);

/// <summary>
/// <see cref="IEchonetLiteHandler.Received"/>イベントにてECHONET Lite フレームを受信した場合に発生するイベント。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ protected virtual void Dispose(bool disposing)
if (disposing) {
FrameReceived = null; // unsubscribe

requestSemaphore?.Dispose();
requestSemaphore = null!;

if (echonetLiteHandler is not null) {
echonetLiteHandler.Received -= EchonetDataReceived;

Expand All @@ -125,6 +128,9 @@ protected virtual async ValueTask DisposeAsyncCore()
{
FrameReceived = null; // unsubscribe

requestSemaphore?.Dispose();
requestSemaphore = null!;

if (echonetLiteHandler is not null) {
echonetLiteHandler.Received -= EchonetDataReceived;

Expand Down

0 comments on commit c1d4c45

Please sign in to comment.