diff --git a/README.md b/README.md index 6ae6c2f..a00ac28 100644 --- a/README.md +++ b/README.md @@ -106,5 +106,5 @@ The `MsBuildPipeLogger.Logger` recognizes these parameters, separated by a `;` a ### A note on concurrency -The `AnonymousPipeLoggerServer.Read()` and `NamedPipeLoggerServer.Read()` methods both block while waiting for additional events. If you need to support concurrency or cancellation, you'll need to wrap this call however is appropriate for your application. +The `AnonymousPipeLoggerServer.Read()` and `NamedPipeLoggerServer.Read()` methods both block while waiting for events. If you need to support concurrency or cancellation, pass a `CancellationToken` to the server constructors and then cancel it during read operations. diff --git a/src/MsBuildPipeLogger.Server/NamedPipeLoggerServer.cs b/src/MsBuildPipeLogger.Server/NamedPipeLoggerServer.cs index 87096b5..8121c95 100644 --- a/src/MsBuildPipeLogger.Server/NamedPipeLoggerServer.cs +++ b/src/MsBuildPipeLogger.Server/NamedPipeLoggerServer.cs @@ -10,6 +10,8 @@ namespace MsBuildPipeLogger /// public class NamedPipeLoggerServer : PipeLoggerServer { + private readonly InterlockedBool _connected = new InterlockedBool(false); + public string PipeName { get; } /// @@ -38,9 +40,7 @@ protected override void Connect() PipeStream.WaitForConnection(); _connected.Set(); } - - private readonly InterlockedBool _connected = new InterlockedBool(false); - + private void CancelConnectionWait() { if(!_connected.Set())