Kanäle mit StornierungTokenSource mit Timeout -Speicher -Leck nach der EntsorgungC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Kanäle mit StornierungTokenSource mit Timeout -Speicher -Leck nach der Entsorgung

Post by Anonymous »

Der vollständige reproduzierbare Code befindet sich auf GitHub, der Speicher wird nach dem Start der ausführbaren Datei bald raketen. Der Code befindet sich hauptsächlich in AsyncBlockingQueue.cs Klasse.

Code: Select all

        public async Task DequeueAsync(
int timeoutInMs = -1,
CancellationToken cancellationToken = default)
{
try
{
using (CancellationTokenSource cts = this.GetCancellationTokenSource(timeoutInMs, cancellationToken))
{
T value = await this._channel.Reader.ReadAsync(cts?.Token ?? cancellationToken).ConfigureAwait(false);
return value;
}
}
catch (ChannelClosedException cce)
{
await Console.Error.WriteLineAsync("Channel is closed.");
throw new ObjectDisposedException("Queue is disposed");
}
catch (OperationCanceledException)
{
throw;
}
catch (Exception ex)
{
await Console.Error.WriteLineAsync("Dequeue failed.");
throw;
}
}

private CancellationTokenSource GetCancellationTokenSource(
int timeoutInMs,
CancellationToken cancellationToken)
{
if (timeoutInMs 
Wenn auf diese Weise verwendet wird, hat es Speicherlecks: < /p>
try
{
string message = await this._inputQueue.DequeueAsync(10,cancellationToken).ConfigureAwait(false);
}
catch(OperationCanceledException){
// timeout
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post