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.Net.WebSockets;
using System.Text; using System.Text;
using pacMan.Interfaces; using pacMan.Interfaces;
@ -9,7 +8,7 @@ namespace pacMan.Services;
public class WebSocketService : IWebSocketService public class WebSocketService : IWebSocketService
{ {
private readonly ILogger<WebSocketService> _logger; private readonly ILogger<WebSocketService> _logger;
private readonly BlockingCollection<WebSocket> _webSockets = new(); private readonly SynchronizedCollection<WebSocket> _webSockets = new();
public WebSocketService(ILogger<WebSocketService> logger) public WebSocketService(ILogger<WebSocketService> logger)
{ {
@ -23,9 +22,9 @@ public class WebSocketService : IWebSocketService
_logger.Log(LogLevel.Debug, "WebSocket added to list"); _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"); _logger.Log(LogLevel.Debug, "WebSocket removed from list");
return taken; return taken;
} }

View File

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