# Ack All (/sdks/csharp/how-to/queues/ack-all)



## Overview [#overview]

`AckAllQueueMessagesAsync` acknowledges **every pending message on a channel in a single broker-side call**, without receiving them first. Reach for it when you want to *drain* a queue rather than *process* it — clearing a backlog of stale work after a bad deploy, resetting a channel between test runs, or discarding messages that are no longer relevant — where pulling and acking each message individually would be slow and wasteful.

Because it settles the whole channel at once, it is far cheaper than a receive-then-ack loop: the broker confirms all in-flight messages atomically and reports how many were affected via `AffectedMessages` on the result.

**Gotchas:** this is a blunt, irreversible instrument — it acknowledges *all* currently-pending messages, not a selected subset, so anything unprocessed is discarded, not redelivered. It settles only messages already visible to the broker at call time, so a busy channel can still receive new messages after the call returns. For routine, per-message cleanup use `CreateQueueDownstreamReceiverAsync` with selective ack or nack, or a [dead-letter policy](/sdks/csharp/how-to/queues/dead-letter-policy) instead — save ack-all for deliberate, wholesale purges.

## Prerequisites [#prerequisites]

* KubeMQ server running on `localhost:50000`
* C# SDK installed (`dotnet add package KubeMQ.SDK.CSharp`)

## Code [#code]

```csharp title="Program.cs"
// KubeMQ .NET SDK — Queues: Simple AckAll
//
// This example demonstrates acknowledging all pending messages in a queue channel
// using the simple AckAllQueueMessagesAsync API (no stream transaction required).
//
// Prerequisites:
//   - KubeMQ server running on localhost:50000
//   - Send some messages to "csharp-queues.ack-all-simple" first
//   - dotnet run

using KubeMQ.Sdk.Client;

await using var client = new KubeMQClient(new KubeMQClientOptions
{
    ClientId = "csharp-queues-ack-all-simple-client",
});
await client.ConnectAsync();

Console.WriteLine("Connected to KubeMQ server");

var result = await client.AckAllQueueMessagesAsync("csharp-queues.ack-all-simple");
Console.WriteLine($"Acknowledged {result.AffectedMessages} messages");

Console.WriteLine("Done.");

```

## How It Works [#how-it-works]

* `AckAllQueueMessagesAsync(channelName)` is a management-plane call that bulk-acknowledges all pending messages on the named channel without requiring a consumer to receive them first.
* This is a one-shot operation: messages are removed from the queue immediately. Use it for queue draining (e.g., after a failed deployment) rather than normal processing.
* The returned result includes `AffectedMessages` — the count of messages that were acknowledged.
* For transactional per-message processing with selective ack or nack, use `CreateQueueDownstreamReceiverAsync` + `PollAsync` instead.

## Related [#related]

* [Pattern overview](/learn/queues/getting-started)
* [C# SDK Reference](/sdks/csharp/reference)
* [Send & Receive](/sdks/csharp/tutorials/send-receive)
* [Ack & Reject](/sdks/csharp/how-to/queues/ack-reject)
