Skip to content

Commit

Permalink
Added removing of debugger event hooks, if disposing of the DebuggerS…
Browse files Browse the repository at this point in the history
…erver object.
  • Loading branch information
CartBlanche committed Apr 5, 2024
1 parent 4215d12 commit 216ce56
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Source/v2/Meadow.Hcom/Debugging/DebuggingServer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Buffers;
using Microsoft.Extensions.Logging;
using System.Buffers;
using System.Collections.Concurrent;
using System.Net;
using System.Net.Sockets;
Expand Down Expand Up @@ -192,7 +193,13 @@ internal ActiveClient(IMeadowConnection connection, TcpClient tcpClient, ILogger
_receiveVsDebugDataTask = Task.Factory.StartNew(SendToMeadowAsync, TaskCreationOptions.LongRunning);
_receiveMeadowDebugDataTask = Task.Factory.StartNew(SendToVisualStudio, TaskCreationOptions.LongRunning);

_connection.DebuggerMessageReceived += (s, e) => _debuggerMessages.Add(e);
_connection.DebuggerMessageReceived += MeadowConnection_DebuggerMessageReceived;
}

private void MeadowConnection_DebuggerMessageReceived(object sender, byte[] e)
{
_logger?.LogDebug("Debugger Message Received, Adding to collection");
_debuggerMessages.Add(e);
}

private const int RECEIVE_BUFFER_SIZE = 256;
Expand Down Expand Up @@ -330,6 +337,11 @@ public void Dispose()
_tcpClient.Dispose();
_networkStream.Dispose();
_cts.Dispose();

if (_connection != null)
{
_connection.DebuggerMessageReceived -= MeadowConnection_DebuggerMessageReceived;
}
Disposed = true;
}
}
Expand Down

0 comments on commit 216ce56

Please sign in to comment.