Unclog threadpool (#27)

This commit is contained in:
2023-11-26 03:22:50 +01:00
committed by GitHub
parent 46af9b97cd
commit 355c24d582
4 changed files with 10 additions and 8 deletions
+3 -3
View File
@@ -5,13 +5,13 @@
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<ApplicationIcon />
<StartupObject />
<Version>5.5.1</Version>
<Version>5.5.2</Version>
<LangVersion>latest</LangVersion>
<Authors>Alexandru-Victor Macocian</Authors>
<Product>MTSC</Product>
<Description>Modular TCP Server and Client</Description>
<AssemblyVersion>5.5.1.0</AssemblyVersion>
<FileVersion>5.5.1.0</FileVersion>
<AssemblyVersion>5.5.2.0</AssemblyVersion>
<FileVersion>5.5.2.0</FileVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Platforms>AnyCPU;x64</Platforms>
<PackageProjectUrl>https://github.com/AlexMacocian/MTSC</PackageProjectUrl>
@@ -50,14 +50,14 @@ namespace MTSC.ServerSide.Listeners
}
this.socket.Listen(50);
Task.Run(async () =>
new TaskFactory().StartNew(async () =>
{
while (this.socket is not null)
{
var clientSocket = await this.socket.AcceptAsync();
this.acceptedSockets.Enqueue(clientSocket);
}
});
}, TaskCreationOptions.LongRunning);
}
}
@@ -8,9 +8,11 @@ namespace MTSC.ServerSide.Schedulers
{
public sealed class FireTasksAndForgetScheduler : IScheduler
{
private readonly TaskFactory taskFactory = new TaskFactory();
public void ScheduleBackgroundService(BackgroundServiceBase backgroundServiceBase)
{
Task.Run(() => backgroundServiceBase.Execute());
this.taskFactory.StartNew(() => backgroundServiceBase.Execute(), TaskCreationOptions.LongRunning);
}
public void ScheduleHandling(List<(ClientData, IConsumerQueue<Message>)> clientsQueues, Action<ClientData, IConsumerQueue<Message>> messageHandlingProcedure)
@@ -18,7 +20,7 @@ namespace MTSC.ServerSide.Schedulers
foreach(var tuple in clientsQueues)
{
(var client, var messageQueue) = tuple;
Task.Run(() => messageHandlingProcedure.Invoke(client, messageQueue));
this.taskFactory.StartNew(() => messageHandlingProcedure.Invoke(client, messageQueue), TaskCreationOptions.LongRunning);
}
}
}
+1 -1
View File
@@ -513,7 +513,7 @@ namespace MTSC.ServerSide
{
var client = this.Listener.AcceptSocket();
var clientStruct = new ClientData(client);
Task.Run(() => this.AcceptClient(clientStruct));
new TaskFactory().StartNew(() => this.AcceptClient(clientStruct), this.cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current);
}
}
catch (Exception e)