Why Disposing a Lifetime Should Release a Hold, Not Kill the Shared Worker
In mobile applications, multiple activations often share a single background worker, making naive disposal of IDisposable lifetimes dangerous. If disposing a lifetime unconditionally stops the shared worker, one activation can silently tear down resources still needed by another. The safer design treats a lifetime as a hold on shared work, where the worker only stops when the last hold is released. This requires atomic synchronization for both start and stop transitions, and each hold must be bound to the specific run it joined to prevent stale releases from affecting restarted workers. Defensive cleanup code across multiple branches deserves the same scrutiny, as any branch performing terminal teardown can shut down a resource still in active use.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in