Changed Collection to SynchronizedCollection

This commit is contained in:
Martin Berg Alstad 2023-05-18 12:05:22 +02:00
parent 4d7b0e2b1e
commit ef85dec657
2 changed files with 4 additions and 4 deletions

View File

@ -1,4 +1,3 @@
using System.Collections.Concurrent;
using System.Net.WebSockets;
using System.Text;
using pacMan.Interfaces;
@ -9,7 +8,7 @@ namespace pacMan.Services;
public class WebSocketService : IWebSocketService
{
private readonly ILogger<WebSocketService> _logger;
private readonly BlockingCollection<WebSocket> _webSockets = new();
private readonly SynchronizedCollection<WebSocket> _webSockets = new();
public WebSocketService(ILogger<WebSocketService> logger)
{
@ -23,9 +22,9 @@ public class WebSocketService : IWebSocketService
_logger.Log(LogLevel.Debug, "WebSocket added to list");
}
public bool Remove(WebSocket? webSocket)
public bool Remove(WebSocket webSocket)
{
var taken = _webSockets.TryTake(out webSocket);
var taken = _webSockets.Remove(webSocket);
_logger.Log(LogLevel.Debug, "WebSocket removed from list");
return taken;
}

View File

@ -20,6 +20,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.ServiceModel.Primitives" Version="4.10.2" />
</ItemGroup>
<ItemGroup>