---
title: Cancel
framework: driverkit
role: symbol
role_heading: Instance Method
path: driverkit/iodispatchqueue/cancel
---

# Cancel

Stops the queue from dequeueing any further tasks, and notifies the specified handler when all in-flight tasks finish.

## Declaration

```occ
kern_return_t Cancel(IODispatchQueueCancelHandler handler);
```

## Parameters

- `handler`: The block to execute when the queue finishes all in-flight work.

## Return Value

Return Value kIOReturnSuccess on success, or another value if an error occurs. For a list of error codes, see Error Codes.

## Discussion

Discussion This method asynchronously tells the dispatch queue to stop the execution of queued tasks, and returns immediately. If a task is already executing, that task runs to completion. After all tasks finish, the dispatch queue executes the block in the handler parameter.

## See Also

### Stopping the Queue

- [IODispatchQueueCancelHandler](driverkit/iodispatchqueuecancelhandler.md)
