<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: -",
    "macOS: 27.0.0 -",
    "tvOS: 27.0.0 -",
    "visionOS: 27.0.0 -",
    "watchOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppIntents",
  "identifier" : "/documentation/AppIntents/LongRunningIntent/performBackgroundTask(options:operation:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "App Intents",
      "AppIntents"
    ],
    "preciseIdentifier" : "s:10AppIntents17LongRunningIntentPAAE21performBackgroundTask7options9operationqd__AA0cdH7OptionsV_qd__yYaKctYaKlF"
  },
  "title" : "performBackgroundTask(options:operation:)"
}
-->

# performBackgroundTask(options:operation:)

Runs an operation in the background with an extended amount of time.

```
@discardableResult func performBackgroundTask<T>(options: LongRunningTaskOptions = [], operation: @escaping () async throws -> T) async throws -> T
```

## Parameters

`options`

Additional options to configure the runtime behavior. For example, you
might use this parameter to tell the system that your task requires GPU resources.
The default value for this parameter is an empty set.

`operation`

The closure to run in the background. Use this closure to specify the
code for your app intent’s task. The closure takes no parameters and returns a type
that you specify.

## Return Value

The value you return from the `operation` closure.

## Discussion> Throws: Throws an error if the operation fails or the system can’t run the operation.

Use this method to wrap long-running code in your app intent’s [`perform()`](/documentation/AppIntents/AppIntent/perform()) method.
This method automatically extends the amount of time your code has to run in the background
past the standard 30-second limit present on some platforms. You don’t have to start a
separate background task.

While your operation runs, provide regular progress updates using the [`progress`](/documentation/AppIntents/ProgressReportingIntent/progress)
property of the [`ProgressReportingIntent`](/documentation/AppIntents/ProgressReportingIntent) protocol. If you don’t update this
property regularly, the system can cancel the background runtime extension and end your
task prematurely.

Live Activities displays the progress of your app intent’s task using information it receives
automatically from this method. Live Activities displays the values of the
<doc://com.apple.documentation/documentation/Foundation/Progress/localizedDescription> and
<doc://com.apple.documentation/documentation/Foundation/Progress/localizedAdditionalDescription>
properties as the title and subtitle of your task. It also displays a progress bar, which it
configures using the values in the <doc://com.apple.documentation/documentation/Foundation/Progress/completedUnitCount>
and <doc://com.apple.documentation/documentation/Foundation/Progress/totalUnitCount> properties.

The following example shows the [`perform()`](/documentation/AppIntents/AppIntent/perform()) method of an app intent, which uses
this method to extend the background runtime of the task. The method implementation uploads
a file in chunks and updates progress values after each chunk.

```swift
func perform() async throws -> some IntentResult & ReturnsValue<String> {
    let result = try await performBackgroundTask {
        progress.totalUnitCount = 100
        progress.localizedDescription = "Uploading file"

        for chunk in 0..<100 {
            try Task.checkCancellation()
            await uploadChunk(chunk)
            progress.completedUnitCount = Int64(chunk + 1)
            progress.localizedAdditionalDescription = "\(chunk + 1)% complete"
        }
        return "Upload complete!"
    }

    return .result(value: result)
}
```

---

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)