feat: switch to Task.Run
This commit is contained in:
parent
22682eb89b
commit
2bd6db75d5
2 changed files with 4 additions and 4 deletions
|
@ -81,7 +81,7 @@ public class AuthSession : TcpSession
|
||||||
RawPacket rawPacket = new RawPacket((OperationCode)opCode, dataBuffer, clientAliveTime, buffer[0],
|
RawPacket rawPacket = new RawPacket((OperationCode)opCode, dataBuffer, clientAliveTime, buffer[0],
|
||||||
buffer[3],
|
buffer[3],
|
||||||
Id, this);
|
Id, this);
|
||||||
Parallel.Invoke(() => _mediator.Send(rawPacket));
|
Task.Run(() => _mediator.Send(rawPacket));
|
||||||
_logger.LogInformation("Connection from: {@RemoteEndpoint}", Socket.RemoteEndPoint?.ToString());
|
_logger.LogInformation("Connection from: {@RemoteEndpoint}", Socket.RemoteEndPoint?.ToString());
|
||||||
base.OnReceived(decryptedBuffer.ToArray(), offset, decryptedBuffer.Length);
|
base.OnReceived(decryptedBuffer.ToArray(), offset, decryptedBuffer.Length);
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,17 +77,17 @@ public class PacketDistributorService : IHostedService
|
||||||
|
|
||||||
public void AddPacket(RawPacket rawPacket)
|
public void AddPacket(RawPacket rawPacket)
|
||||||
{
|
{
|
||||||
|
_concurrentQueue.Enqueue(rawPacket);
|
||||||
|
Task.Run(() => DequeueAndProcessAsync());
|
||||||
_logger.LogInformation("Packet with ID: {MessageOperationCode} has been received",
|
_logger.LogInformation("Packet with ID: {MessageOperationCode} has been received",
|
||||||
rawPacket.OperationCode);
|
rawPacket.OperationCode);
|
||||||
_concurrentQueue.Enqueue(rawPacket);
|
|
||||||
Parallel.Invoke(() => DequeueAndProcessAsync());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task DequeueAndProcessAsync()
|
private async Task DequeueAndProcessAsync()
|
||||||
{
|
{
|
||||||
if (_concurrentQueue.TryDequeue(out var item))
|
if (_concurrentQueue.TryDequeue(out var item))
|
||||||
{
|
{
|
||||||
Parallel.Invoke(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
_logger.LogTrace("[{TempId}] Packet with ID: {MessageOperationCode} is being dequeued",
|
_logger.LogTrace("[{TempId}] Packet with ID: {MessageOperationCode} is being dequeued",
|
||||||
item.Session.Id, item.OperationCode);
|
item.Session.Id, item.OperationCode);
|
||||||
|
|
Loading…
Reference in a new issue