From 29f40b88af0a04b30752ce7b15daba546461bbe7 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Thu, 16 Oct 2025 13:09:52 +0200 Subject: [PATCH] Use private readonly object for locking --- FFMpegCore/FFMpeg/Arguments/PipeArgument.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/FFMpegCore/FFMpeg/Arguments/PipeArgument.cs b/FFMpegCore/FFMpeg/Arguments/PipeArgument.cs index 3b03866..69fd990 100644 --- a/FFMpegCore/FFMpeg/Arguments/PipeArgument.cs +++ b/FFMpegCore/FFMpeg/Arguments/PipeArgument.cs @@ -7,10 +7,12 @@ namespace FFMpegCore.Arguments; public abstract class PipeArgument { private readonly PipeDirection _direction; + private readonly object _pipeLock; protected PipeArgument(PipeDirection direction) { PipeName = PipeHelpers.GetUnqiuePipeName(); + _pipeLock = new object(); _direction = direction; } @@ -33,7 +35,7 @@ public abstract class PipeArgument public void Post() { Debug.WriteLine($"Disposing NamedPipeServerStream on {GetType().Name}"); - lock (Pipe) + lock (_pipeLock) { Pipe?.Dispose(); Pipe = null!; @@ -53,11 +55,7 @@ public abstract class PipeArgument finally { Debug.WriteLine($"Disconnecting NamedPipeServerStream on {GetType().Name}"); - - //if Pipe is null, then the lock doesnt matter, - //Because the next code will not execute anyways. - //so we can use a new object - lock (Pipe ?? new object()) + lock (_pipeLock) { if (Pipe is { IsConnected: true }) {