This commit is contained in:
Ashish 2025-09-09 14:29:55 +08:00 committed by GitHub
commit 248469544f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -31,8 +31,12 @@ namespace FFMpegCore.Arguments
public void Post()
{
Debug.WriteLine($"Disposing NamedPipeServerStream on {GetType().Name}");
Pipe?.Dispose();
Pipe = null!;
lock(Pipe)
{
Pipe?.Dispose();
Pipe = null!;
}
}
public async Task During(CancellationToken cancellationToken = default)
@ -48,9 +52,15 @@ namespace FFMpegCore.Arguments
finally
{
Debug.WriteLine($"Disconnecting NamedPipeServerStream on {GetType().Name}");
if (Pipe is { IsConnected: true })
lock (Pipe ?? new object())
//if Pipe is null, then the lock doesnt matter,
//Because the next code will not execute anyways.
//so we can use a new object
{
Pipe.Disconnect();
if (Pipe is { IsConnected: true })
{
Pipe.Disconnect();
}
}
}
}