# WinNamedPipesLib Package
{: .no_toc }

The **WinNamedPipesLib** built-in package exposes Windows named pipes as twinBASIC objects with an asynchronous, IOCP-driven I/O model. One process hosts a [**NamedPipeServer**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md); other processes use a [**NamedPipeClientManager**](/tB/Packages/WinNamedPipesLib/NamedPipeClientManager.md) to open one or more [**NamedPipeClientConnection**](/tB/Packages/WinNamedPipesLib/NamedPipeClientConnection.md) instances to it. Writes complete in the background; messages and connection-lifecycle changes are delivered as events.

The package is a built-in package shipped with twinBASIC. Add it through Project → References... (**Ctrl-T**) → the **Available Packages** tab.

* TOC
{:toc}

## Architecture

Two halves, each one user-instantiated coordinator class plus one per-connection class:

| Side    | Coordinator                                            | Per-connection                                                 |
|---------|--------------------------------------------------------|----------------------------------------------------------------|
| Server  | [**NamedPipeServer**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md)                 | [**NamedPipeServerConnection**](/tB/Packages/WinNamedPipesLib/NamedPipeServerConnection.md)     |
| Client  | [**NamedPipeClientManager**](/tB/Packages/WinNamedPipesLib/NamedPipeClientManager.md)   | [**NamedPipeClientConnection**](/tB/Packages/WinNamedPipesLib/NamedPipeClientConnection.md)     |

The server publishes a name (`PipeName = "MyService"` → Win32 path `\\.\pipe\MyService`) and returns a [**NamedPipeServerConnection**](/tB/Packages/WinNamedPipesLib/NamedPipeServerConnection.md) for every client that connects. The client manager dials by the same name (with [**Connect**](/tB/Packages/WinNamedPipesLib/NamedPipeClientManager.md#connect)) and returns a [**NamedPipeClientConnection**](/tB/Packages/WinNamedPipesLib/NamedPipeClientConnection.md). The two ends are symmetric thereafter --- both expose `AsyncRead`, `AsyncWrite`, and `AsyncClose` with the same signatures.

Reads, writes, and connection completion all run through the same Windows I/O Completion Port (IOCP) infrastructure. Each coordinator class owns its own completion port, a configurable pool of worker threads ([**NumThreadsIOCP**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#numthreadsiocp)), and a hidden message-only window used to marshal events back to the UI thread.

## Event delivery --- marshalled vs free-threaded

By default events fire on the main UI thread. The IOCP worker threads receive each completion, package the buffer, and `PostMessage` the result to a hidden `STATIC`-class window owned by the coordinator. The window's subclassed `WndProc` then raises the BASIC event from the message loop. This means the consuming process **must be pumping a Win32 message loop** for events to be delivered. Forms-based hosts already are; console hosts and Windows services are not, and need either [**NamedPipeServer.ManualMessageLoopEnter**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#manualmessageloopenter) (and the matching `ManualMessageLoopLeave`) or `FreeThreadingEvents = True`.

Setting [**FreeThreadingEvents**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#freethreadingevents) to **True** skips the marshalling round-trip and raises events directly from the IOCP worker thread. Performance is higher and there is no message-loop requirement, but the consumer's event handlers must be thread-safe --- multiple `ClientMessageReceived` events from different clients can fire concurrently, and global / class state touched from the handler is **not** protected by the implicit UI-thread serialisation that the default mode provides.

The flag must be set before [**Start**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#start) (server side) or before the first [**Connect**](/tB/Packages/WinNamedPipesLib/NamedPipeClientManager.md#connect) call (client side); it is read once and propagated to every per-connection object.

## Hosting inside a Windows service
{: #service-host-idiom }

Windows services hosted through the [**WinServicesLib**](/tB/Packages/WinServicesLib/index.md) package run into the message-loop dependency described above when they also host a [**NamedPipeServer**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md): the [**ITbService.EntryPoint**](/tB/Packages/WinServicesLib/ITbService.md#entrypoint) thread is not pumping messages by default, so the marshalled-event delivery has nothing to dispatch through. The package provides [**NamedPipeServer.ManualMessageLoopEnter**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#manualmessageloopenter) / [**ManualMessageLoopLeave**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#manualmessageloopleave) for exactly this case.

The canonical pattern: [**ITbService.EntryPoint**](/tB/Packages/WinServicesLib/ITbService.md#entrypoint) opens the server, transitions the service to `Running`, blocks inside [**ManualMessageLoopEnter**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#manualmessageloopenter), and only leaves the loop when [**ITbService.ChangeState**](/tB/Packages/WinServicesLib/ITbService.md#changestate) --- running on the *other* (dispatcher) thread --- calls [**ManualMessageLoopLeave**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#manualmessageloopleave) on the same server instance.

```tb check_build concat_group=pipe-service-host
Private NamedPipeServer As NamedPipeServer     ' shared by the two threads

' On the service-entry-point thread:
Sub EntryPoint(ByVal ServiceManager As ServiceManager) _
        Implements ITbService.EntryPoint
    Set NamedPipeServer = New NamedPipeServer
    NamedPipeServer.PipeName = "MyServicePipe"

    ' (tell the SCM the service is running, then block on the message loop)
    ServiceManager.ReportStatus vbServiceStatusRunning
    NamedPipeServer.Start
    NamedPipeServer.ManualMessageLoopEnter      ' blocks until ManualMessageLoopLeave
    NamedPipeServer.Stop

    ServiceManager.ReportStatus vbServiceStatusStopped
End Sub

' On the dispatcher thread:
Sub ChangeState(ByVal ServiceManager As ServiceManager, _
                ByVal dwControl As ServiceControlCodeConstants, _
                ByVal dwEventType As Long, _
                ByVal lpEventData As LongPtr) _
        Implements ITbService.ChangeState
    Select Case dwControl
        Case vbServiceControlStop, vbServiceControlShutdown
            ServiceManager.ReportStatus vbServiceStatusStopPending
            NamedPipeServer.ManualMessageLoopLeave   ' wakes the service thread out of ManualMessageLoopEnter
    End Select
End Sub
```

Three facts worth pulling out:

- The service entry-point and the control-code handler run on **different threads**. The shared [**NamedPipeServer**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md) member field is what they coordinate through; the handler calls [**ManualMessageLoopLeave**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#manualmessageloopleave) on it to wake the entry-point.
- [**ManualMessageLoopLeave**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#manualmessageloopleave) is the only way to exit [**ManualMessageLoopEnter**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#manualmessageloopenter) cleanly. There is no timeout and no second blocking primitive. Services that need to react to other wake-up sources (e.g. a *Pause* control code) set a shared `Public` flag *then* call [**ManualMessageLoopLeave**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#manualmessageloopleave) to break out, inspect the flag, and re-enter the loop or proceed to shutdown.
- [**FreeThreadingEvents**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#freethreadingevents) = **False** (the default) is **required** for this pattern. Setting it to **True** would deliver events directly on the IOCP worker thread and bypass the manual loop entirely -- the pipe still works, but `ManualMessageLoopEnter` / `Leave` become irrelevant. Pick one mode and stay with it.

The non-service equivalent --- hosting the same [**NamedPipeServer**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md) inside a Form --- is simpler: the Form's regular message loop pumps the marshalling window automatically, so the Form calls [**Start**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#start) in `Form_Load`, [**Stop**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#stop) in `Form_Unload`, and never touches [**ManualMessageLoopEnter**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#manualmessageloopenter) / [**ManualMessageLoopLeave**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#manualmessageloopleave). Either pattern works; the service-host pattern is the one that needs the manual pump.

## Asynchronous reads

When [**ContinuouslyReadFromPipe**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#continuouslyreadfrompipe) is **True** (the default), the package keeps a read pending against every connection at all times --- every [**ClientMessageReceived**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#clientmessagereceived) / [**MessageReceived**](/tB/Packages/WinNamedPipesLib/NamedPipeClientConnection.md#messagereceived) event is followed by another `AsyncRead` issued from inside the IOCP thread. Set the flag to **False** to handle reads one-at-a-time: each event handler must then call [**NamedPipeServerConnection.AsyncRead**](/tB/Packages/WinNamedPipesLib/NamedPipeServerConnection.md#asyncread) / [**NamedPipeClientConnection.AsyncRead**](/tB/Packages/WinNamedPipesLib/NamedPipeClientConnection.md#asyncread) to receive the next message. This is useful for back-pressure when the consumer can't process messages as fast as they arrive.

## The cookie correlation pattern

Every [**AsyncRead**](/tB/Packages/WinNamedPipesLib/NamedPipeServerConnection.md#asyncread) and [**AsyncWrite**](/tB/Packages/WinNamedPipesLib/NamedPipeServerConnection.md#asyncwrite) accepts an optional *Cookie* of type **Variant**. Whatever value the caller passes in is round-tripped through the IOCP completion and re-emitted as the *Cookie* parameter of the matching [**ClientMessageReceived**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#clientmessagereceived) / [**ClientMessageSent**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#clientmessagesent) (or client-side [**MessageReceived**](/tB/Packages/WinNamedPipesLib/NamedPipeClientConnection.md#messagereceived) / [**MessageSent**](/tB/Packages/WinNamedPipesLib/NamedPipeClientConnection.md#messagesent)) event. Use this to correlate event callbacks with the calls that initiated them --- a per-request sequence number, a callback object, a key into a pending-replies dictionary.

```tb check_build concat_group=cookie-correlation
Private WithEvents connection As NamedPipeClientConnection
Private pending As New Collection

Private Sub SendRequest(text As String, replyHandler As IReplyHandler)
    Dim cookie As Long = NextCookie()
    pending.Add replyHandler, CStr(cookie)
    connection.AsyncWrite Encode(text), cookie
End Sub

Private Sub connection_MessageReceived(ByRef Cookie As Variant, ByRef Data() As Byte)
    Dim handler As IReplyHandler = pending(CStr(Cookie))
    pending.Remove CStr(Cookie)
    handler.HandleReply Decode(Data)
End Sub
```

## Working with `Data() As Byte` in events

The *Data* parameter on [**ClientMessageReceived**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#clientmessagereceived) and [**MessageReceived**](/tB/Packages/WinNamedPipesLib/NamedPipeClientConnection.md#messagereceived) is **not** a normal heap-allocated **Byte** array. The package constructs a custom `SAFEARRAY` whose backing memory points at the IOCP read buffer, then clears the array pointer at the end of the event handler so the buffer can be recycled. The values are valid *only* while the handler is on the stack.

> [!IMPORTANT]
> Copy the bytes out before the event handler returns if they are needed later. Storing the array reference in a module-level variable, a **Collection**, or a class field leaves a dangling pointer once the IOCP loop reuses the buffer for the next message.

For a fresh **Byte()** copy:

```tb check_build
Dim Data() As Byte     ' the event handler's own ByRef parameter
Dim Stored() As Byte
ReDim Stored(UBound(Data))
[_HiddenModule].vbaCopyBytes UBound(Data) + 1, VarPtr(Stored(0)), VarPtr(Data(0))
```

For a text payload, `StrConv(Data, vbUnicode)` (UTF-8) or `CStr` over a `vbUnicode`-converted copy reads the bytes immediately and produces an owned **String** in one step.

## Recommended payload encoding: `PropertyBag`
{: #propertybag-carrier }

The package transports raw bytes; it is agnostic about what is inside them. For non-trivial protocols the recommended carrier is [**PropertyBag**](/tB/Packages/VBRUN/PropertyBag/index.md) --- twinBASIC's built-in keyed-property serialiser. Two reasons:

1. **`PropertyBag.Contents` deep-copies the bytes**, which is the simplest answer to the transient-`Data()` lifetime caveat above. Assigning *Data* to a fresh **PropertyBag**'s **Contents** captures the buffer in one step; the copy is safe to retain past the event handler.
2. **`PropertyBag` provides typed multi-field payloads** without the consumer having to design a wire protocol. Both sides agree on property names (e.g. `"CommandID"`, `"ResponseCommandID"`, `"Data"`) and **PropertyBag** handles the byte-level encoding.

```tb check_build
' Sender -- the client:
Private Sub AskForTheTime(ByVal connection As NamedPipeClientConnection)
    Dim request As New PropertyBag
    request.WriteProperty "CommandID", "WHAT_TIME_IS_IT"
    connection.AsyncWrite request.Contents
End Sub
```

```tb check_build
' Receiver -- the server:
Private Sub server_ClientMessageReceived( _
        Connection As NamedPipeServerConnection, _
        ByRef Cookie As Variant, _
        ByRef Data() As Byte)
    Dim incoming As New PropertyBag
    incoming.Contents = Data        ' deep-copies the bytes; safe to use past the handler

    Dim cmd As String = incoming.ReadProperty("CommandID")
    Select Case cmd
        Case "WHAT_TIME_IS_IT"
            Dim reply As New PropertyBag
            reply.WriteProperty "ResponseCommandID", cmd
            reply.WriteProperty "ResponseData", Time()
            Connection.AsyncWrite reply.Contents
    End Select
End Sub
```

Nothing in the package mandates **PropertyBag** --- raw `Byte()` works too, and a custom wire format may be the right answer for very high-throughput scenarios. The everyday case is well served by the **PropertyBag** convention, and it solves the transient-`Data()` problem without extra effort.

## Closing a client connection

> [!IMPORTANT]
> The **`_README.txt`** states: *"you MUST call **AsyncClose** on the client side, otherwise the connection is left alive when the object goes out of scope"*.

Either let the [**NamedPipeClientConnection**](/tB/Packages/WinNamedPipesLib/NamedPipeClientConnection.md) object terminate cleanly through its `Class_Terminate` (which calls [**AsyncClose**](/tB/Packages/WinNamedPipesLib/NamedPipeClientConnection.md#asyncclose) automatically) **or** call [**AsyncClose**](/tB/Packages/WinNamedPipesLib/NamedPipeClientConnection.md#asyncclose) explicitly before dropping the last reference. Holding a reference forever --- for example in a long-lived module-level **Collection** --- without calling [**AsyncClose**](/tB/Packages/WinNamedPipesLib/NamedPipeClientConnection.md#asyncclose) keeps the underlying pipe handle open and the IOCP thread alive.

## Discovering pipes

[**NamedPipeClientManager.FindNamedPipes**](/tB/Packages/WinNamedPipesLib/NamedPipeClientManager.md#findnamedpipes) enumerates the named pipes published on the local machine, returning a **Collection** of **String** names that match an optional `*`/`?` wildcard pattern. The implementation is `FindFirstFileW("\\.\pipe\<Pattern>")` --- the package strips the leading namespace itself, so pass just the pipe name (`"MyService*"`, not `"\\.\pipe\MyService*"`).

Named pipes can appear and disappear at any time as their server processes start and stop, and the package does not publish an event for this. The canonical discovery loop is a low-frequency [**Timer**](/tB/Packages/VB/Timer/index.md) that repopulates a list and preserves the user's current selection --- a few seconds between polls is the typical interval; the underlying `FindFirstFileW` is cheap enough that nothing finer is required:

```tb check_build
Private manager As NamedPipeClientManager

Private Sub timerRefreshNamedPipes_Timer()
    Dim previousSelection As String = lstNamedPipes.List(lstNamedPipes.ListIndex)
    lstNamedPipes.Clear
    Dim restoredIndex As Long = -1
    Dim index As Long = 0
    Dim pipeName As Variant
    For Each pipeName In manager.FindNamedPipes("MyService_*")
        If pipeName = previousSelection Then restoredIndex = index
        lstNamedPipes.AddItem pipeName
        index = index + 1
    Next
    If restoredIndex <> -1 Then lstNamedPipes.ListIndex = restoredIndex
End Sub
```

## Known limitations

- **No `Error` event is raised.** None of the four classes raises an `Error` event. Recognised IOCP failures (`ERROR_BROKEN_PIPE`, `ERROR_OPERATION_ABORTED`) drop the connection silently through the normal [**ClientDisconnected**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#clientdisconnected) / [**Disconnected**](/tB/Packages/WinNamedPipesLib/NamedPipeClientConnection.md#disconnected) path --- the consumer cannot distinguish a deliberate close from a transport failure. Worse, the client-side IOCP loop (`IOCPThreadClient` in `NamedPipeClientManager.twin`) contains a literal **Stop** statement on the branch for *unrecognised* error codes, which halts execution rather than reporting the error to consumer code.
- **Send is hard-capped at** [**MessageBufferSize**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#messagebuffersize) **bytes.** The receive path grows its buffer dynamically on `ERROR_MORE_DATA`, so reads of arbitrary size work. The send path does not: [**AsyncWrite**](/tB/Packages/WinNamedPipesLib/NamedPipeServerConnection.md#asyncwrite) (and the client-side [**AsyncWrite**](/tB/Packages/WinNamedPipesLib/NamedPipeClientConnection.md#asyncwrite)) copies the caller's `Byte()` *without a bounds-check* into a per-completion buffer sized at [**MessageBufferSize**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#messagebuffersize) (default **131072** bytes); the same applies to [**AsyncBroadcast**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#asyncbroadcast). A larger message overruns the buffer --- likely a crash or heap corruption rather than a clean error. Raise [**MessageBufferSize**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#messagebuffersize) above the largest expected message *before* the first [**Start**](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#start) (server) or [**Connect**](/tB/Packages/WinNamedPipesLib/NamedPipeClientManager.md#connect) (client); the value is read once at that point and propagated to every per-connection buffer.

## Classes

- [NamedPipeServer](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md) -- the server: publishes a pipe name, hosts an IOCP loop, raises events for the lifecycle of every accepted client
  - *Fields:* [ContinuouslyReadFromPipe](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#continuouslyreadfrompipe) -- whether a read is kept pending automatically after each received message; [FreeThreadingEvents](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#freethreadingevents) -- whether events fire on the IOCP worker thread instead of the UI thread; [MessageBufferSize](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#messagebuffersize) -- per-completion read / write buffer size in bytes; [NumThreadsIOCP](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#numthreadsiocp) -- number of IOCP worker threads created by Start; [PipeName](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#pipename) -- the leaf name the pipe is published under
  - *Events:* [ClientConnected](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#clientconnected) -- fires when a client's ConnectNamedPipe completes; [ClientDisconnected](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#clientdisconnected) -- fires when a client has dropped and all outstanding I/O has returned; [ClientMessageReceived](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#clientmessagereceived) -- fires when a complete message has been read from a client; [ClientMessageSent](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#clientmessagesent) -- fires when an AsyncWrite or AsyncBroadcast write has completed for a client; [ServerReady](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#serverready) -- fires once, after Start, when all IOCP worker threads are ready and the first listener is published
  - *Methods:* [AsyncBroadcast](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#asyncbroadcast) -- issues an AsyncWrite against every currently-connected client; [ManualMessageLoopEnter](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#manualmessageloopenter) -- runs a Win32 message loop on the calling thread until ManualMessageLoopLeave is called; [ManualMessageLoopLeave](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#manualmessageloopleave) -- posts a quit message to wake the ManualMessageLoopEnter loop from another thread; [New](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#new) -- constructs the server in the not-yet-started state; [Start](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#start) -- creates the IOCP port, starts worker threads, and publishes the pipe; [Stop](/tB/Packages/WinNamedPipesLib/NamedPipeServer.md#stop) -- shuts down the server, cancels all I/O, and releases all resources
- [NamedPipeServerConnection](/tB/Packages/WinNamedPipesLib/NamedPipeServerConnection.md) -- one server-side per-client connection; the **Connection** parameter of every `NamedPipeServer` event, with its own `AsyncRead` / `AsyncWrite` / `AsyncClose`
  - *Fields:* [CustomData](/tB/Packages/WinNamedPipesLib/NamedPipeServerConnection.md#customdata) -- opaque per-connection slot for consumer-defined state; [Handle](/tB/Packages/WinNamedPipesLib/NamedPipeServerConnection.md#handle) -- the underlying Win32 pipe handle for this connection; [IsConnected](/tB/Packages/WinNamedPipesLib/NamedPipeServerConnection.md#isconnected) -- True while the client is connected; [IsOpening](/tB/Packages/WinNamedPipesLib/NamedPipeServerConnection.md#isopening) -- True during the brief window between object creation and ConnectNamedPipe completing
  - *Methods:* [AsyncClose](/tB/Packages/WinNamedPipesLib/NamedPipeServerConnection.md#asyncclose) -- cancels all outstanding I/O and closes the pipe handle; [AsyncRead](/tB/Packages/WinNamedPipesLib/NamedPipeServerConnection.md#asyncread) -- issues an asynchronous read against this connection; [AsyncWrite](/tB/Packages/WinNamedPipesLib/NamedPipeServerConnection.md#asyncwrite) -- sends a message to this specific client; [New](/tB/Packages/WinNamedPipesLib/NamedPipeServerConnection.md#new) -- constructs a connection object bound to the parent server's IOCP infrastructure (package-private)
- [NamedPipeClientManager](/tB/Packages/WinNamedPipesLib/NamedPipeClientManager.md) -- the client-side coordinator; owns the IOCP loop and the [**Connect**](/tB/Packages/WinNamedPipesLib/NamedPipeClientManager.md#connect) / [**Stop**](/tB/Packages/WinNamedPipesLib/NamedPipeClientManager.md#stop) / [**FindNamedPipes**](/tB/Packages/WinNamedPipesLib/NamedPipeClientManager.md#findnamedpipes) methods
  - *Fields:* [ContinuouslyReadFromPipe](/tB/Packages/WinNamedPipesLib/NamedPipeClientManager.md#continuouslyreadfrompipe) -- whether each connection keeps a read pending automatically after every received message; [FreeThreadingEvents](/tB/Packages/WinNamedPipesLib/NamedPipeClientManager.md#freethreadingevents) -- whether events fire on the IOCP worker thread instead of the UI thread; [MessageBufferSize](/tB/Packages/WinNamedPipesLib/NamedPipeClientManager.md#messagebuffersize) -- per-completion read / write buffer size in bytes; [NumThreadsIOCP](/tB/Packages/WinNamedPipesLib/NamedPipeClientManager.md#numthreadsiocp) -- number of IOCP worker threads created on the first Connect call
  - *Methods:* [Connect](/tB/Packages/WinNamedPipesLib/NamedPipeClientManager.md#connect) -- opens an asynchronous connection to a named pipe and returns a NamedPipeClientConnection; [FindNamedPipes](/tB/Packages/WinNamedPipesLib/NamedPipeClientManager.md#findnamedpipes) -- enumerates named pipes published on the local machine matching an optional wildcard pattern; [New](/tB/Packages/WinNamedPipesLib/NamedPipeClientManager.md#new) -- constructs the manager and its hidden marshalling window in the not-yet-connected state; [Stop](/tB/Packages/WinNamedPipesLib/NamedPipeClientManager.md#stop) -- cancels all I/O, shuts down worker threads, and releases all resources
- [NamedPipeClientConnection](/tB/Packages/WinNamedPipesLib/NamedPipeClientConnection.md) -- one client-side connection; exposes the `Connected` / `Disconnected` / `MessageReceived` / `MessageSent` events and the matching `AsyncRead` / `AsyncWrite` / `AsyncClose` methods
  - *Fields:* [CustomData](/tB/Packages/WinNamedPipesLib/NamedPipeClientConnection.md#customdata) -- opaque per-connection slot for consumer-defined state; [Handle](/tB/Packages/WinNamedPipesLib/NamedPipeClientConnection.md#handle) -- the underlying Win32 pipe handle for this connection; [PipeName](/tB/Packages/WinNamedPipesLib/NamedPipeClientConnection.md#pipename) -- the leaf pipe name this connection was opened against
  - *Events:* [Connected](/tB/Packages/WinNamedPipesLib/NamedPipeClientConnection.md#connected) -- fires once the asynchronous CreateFileW has succeeded and the pipe is ready; [Disconnected](/tB/Packages/WinNamedPipesLib/NamedPipeClientConnection.md#disconnected) -- fires when the pipe has dropped and all outstanding I/O has returned; [MessageReceived](/tB/Packages/WinNamedPipesLib/NamedPipeClientConnection.md#messagereceived) -- fires when a complete message has been read from the pipe; [MessageSent](/tB/Packages/WinNamedPipesLib/NamedPipeClientConnection.md#messagesent) -- fires when a previously-issued AsyncWrite has completed
  - *Methods:* [AsyncClose](/tB/Packages/WinNamedPipesLib/NamedPipeClientConnection.md#asyncclose) -- cancels all outstanding I/O and closes the pipe handle; [AsyncRead](/tB/Packages/WinNamedPipesLib/NamedPipeClientConnection.md#asyncread) -- manually issues an asynchronous read against this connection; [AsyncWrite](/tB/Packages/WinNamedPipesLib/NamedPipeClientConnection.md#asyncwrite) -- sends a message to the server; [New](/tB/Packages/WinNamedPipesLib/NamedPipeClientConnection.md#new) -- constructs a connection object bound to the parent manager's IOCP infrastructure (package-private)
