<!--
{
  "availability" : [
    "iOS: 16.1.0 -",
    "iPadOS: 16.1.0 -",
    "macCatalyst: 16.1.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 18.4.0 -",
    "visionOS: 2.4.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "BackgroundAssets",
  "identifier" : "/documentation/BackgroundAssets/BADownloadManager/withExclusiveControl(_:)-1rf9w",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Background Assets",
      "BackgroundAssets"
    ],
    "preciseIdentifier" : "s:So17BADownloadManagerC16BackgroundAssetsE20withExclusiveControlyxxyKYTcYaKlF"
  },
  "title" : "withExclusiveControl(_:)"
}
-->

# withExclusiveControl(_:)

Attempts to acquire immediate, exclusive control over the download manager.

```
@backDeployed(before: iOS 27, macOS 27, tvOS 27, visionOS 27)
final func withExclusiveControl<ReturnType>(_ body: @escaping () throws -> sending ReturnType) async throws -> sending ReturnType
```

## Parameters

`body`

A closure to execute with exclusive control over the download manager. Once the closure returns or throws, you lose exclusive control.

## Return Value

`body`’s return value.

## Discussion

To avoid races between your main app and your downloader extension, perform operations on the download manager—*e.g.*, fetching current downloads, scheduling new downloads, *etc.*—while maintaining exclusive control over it. Unlike [`withExclusiveControl(_:)`](/documentation/BackgroundAssets/BADownloadManager/withExclusiveControl(_:)-2ang9), this method waits for exclusive control to be acquired and then relinquished before it returns.

> Throws: When `body` throws or when exclusive control over the download manager can’t be acquired.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)