---
title: "ResponseStream.WriteAsync method"
canonical: https://isoplane.dev/docs/reference/sdk/Isoplane.Sdk/Isoplane/ResponseStream/WriteAsync
---

# ResponseStream.WriteAsync method

Sends one piece of the body, and completes when Isoplane has accepted all of it.

```csharp
public ValueTask WriteAsync(ReadOnlyMemory<byte> bytes,
    CancellationToken cancellationToken = default)
```

| parameter         | description                                                                                                                                                                                                                                                              |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| bytes             | The bytes to send. Do not change them until the returned task completes. An empty buffer sends nothing.                                                                                                                                                                  |
| cancellationToken | Stops the handler writing to a client that has gone away; pass [`Aborted`](https://isoplane.dev/docs/reference/sdk/Isoplane.Sdk/Isoplane/RequestHead/Aborted). It is checked before the write begins and again when it finishes; a write in progress is not interrupted. |

## Exceptions

| exception                  | condition                                                                                                                                                    |
| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| InvalidOperationException  | [`Complete`](https://isoplane.dev/docs/reference/sdk/Isoplane.Sdk/Isoplane/ResponseStream/Complete) has been called, or the previous write has not finished. |
| OperationCanceledException | The token was cancelled.                                                                                                                                     |
| IOException                | Isoplane could not accept the piece.                                                                                                                         |

## Remarks

Await each write before starting the next. Awaiting is what keeps the handler from producing output faster than it can be sent.

Once the client has gone away, a write discards its piece and completes, unless its token is cancelled.

## See Also

- class [ResponseStream](https://isoplane.dev/docs/reference/sdk/Isoplane.Sdk/Isoplane/ResponseStream)
- namespace [Isoplane](https://isoplane.dev/docs/reference/sdk/Isoplane.Sdk)
