Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions FFMpegCore/FFMpeg/Arguments/PipeArgument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace FFMpegCore.Arguments;
public abstract class PipeArgument
{
private readonly PipeDirection _direction;
Comment thread
rosenbjerg marked this conversation as resolved.
private readonly object _pipeLock = new();

protected PipeArgument(PipeDirection direction)
{
Expand All @@ -22,19 +23,25 @@ protected PipeArgument(PipeDirection direction)

public void Pre()
{
if (Pipe != null)
lock (_pipeLock)
{
throw new InvalidOperationException("Pipe already has been opened");
}
if (Pipe != null)
{
throw new InvalidOperationException("Pipe already has been opened");
}

Pipe = new NamedPipeServerStream(PipeName, _direction, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
Pipe = new NamedPipeServerStream(PipeName, _direction, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
}
}

public void Post()
{
Debug.WriteLine($"Disposing NamedPipeServerStream on {GetType().Name}");
Pipe?.Dispose();
Pipe = null!;
lock (_pipeLock)
{
Pipe?.Dispose();
Pipe = null!;
}
}

public async Task During(CancellationToken cancellationToken = default)
Expand All @@ -50,9 +57,12 @@ public async Task During(CancellationToken cancellationToken = default)
finally
{
Debug.WriteLine($"Disconnecting NamedPipeServerStream on {GetType().Name}");
if (Pipe is { IsConnected: true })
lock (_pipeLock)
{
Pipe.Disconnect();
if (Pipe is { IsConnected: true })
{
Pipe.Disconnect();
}
}
}
}
Expand Down