Start here. This is the direct spoken answer to practice first.
Why this question matters
Graceful shutdown gives a worker time to stop taking new work and leave in-flight work in a recoverable state. The correct behavior depends on message acknowledgement, idempotency, leases, and the host's finite shutdown window.
A BackgroundService receives a stopping token in ExecuteAsync and should observe it in waits and dependency calls. When shutdown begins, the worker stops accepting new work and either completes the current item within the available window or leaves it recoverable for another attempt. It should not abandon a durable message after acknowledging it, and it should not hold shutdown forever. Cleanup belongs in finally blocks, disposal, or StopAsync according to who owns each resource.