Show / Hide Table of Contents

Class JobManager

An object that manages saving and loading jobs so that they can continue to run if the app is backgrounded or even terminated.

Inheritance
object
JobManager
Namespace: Esri.ArcGISRuntime.Toolkit
Assembly: Esri.ArcGISRuntime.Toolkit.Maui.dll
Syntax
public sealed class JobManager
Remarks

The job manager is instantiable, but the ``shared`` instance is suitable for most applications.

Background
Jobs are long running server operations. When a job instance is started on the client, it makes a request to a service asking it to start work on the server. At that point, the client polls the server intermittently to check the status of the work. Once the work is completed the result is downloaded with a background `URLSession`. This allows the download to complete out of process, and the download task can relaunch the app upon completion, even in the case where the app was terminated.

We do not expect users to keep an application in the foreground and wait for a job to complete. Once the job is started, if the app is backgrounded, we can use an app refresh background task to check the status of the work on the server. If the server work is complete we can start downloading the result in the background at that point. If the work on the server is not complete, we can reschedule another background app refresh to recheck status.

There is some iOS behavior to be aware of as well. In iOS, if an application is backgrounded, the operating system can terminate the app at its discretion. This means that jobs need to be serialized when an app is backgrounded so that if the app is terminated the jobs can be rehydrated upon relaunch of the app.

Also, in iOS, if the user of an app removes the app from the multitasking UI (aka force quits it), the system interprets this as a strong indication that the app should do no more work in the background. The consequences of this are two-fold for jobs. One, any background fetch tasks are not given any time until the app is relaunched again. And two, any background downloads that are in progress are canceled by the operating system.

Features
The job manager is an `ObservableObject` with a mutable ``jobs`` property. Adding a job to this property will allow the job manager to do the work to make sure that we can rehydrate a job if an app is terminated.

As such, the job manager will:

The job manager will help with the lifetime of jobs in other ways as well.

iOS specific behavior: The job manager will ask the system for some background processing time when an app is backgrounded so that jobs that are not yet started on the server, can have some time to allow them to start. This means if you kick off a job and it hasn't actually started on the server when the app is backgrounded, the job should have enough time to start on the server which will cause it to enter into a polling state. When the job reaches the polling state the status of the work on the server can be checked intermittently.

To enable polling while an app is backgrounded, the job manager will request from the system a background refresh task (if enabled via the JobManager.PreferredBackgroundStatusCheckSchedule property). If the system later executes the background refresh task then the job manager will check the status of any running jobs. At that point the jobs may start downloading their result. Note, this does not work on the simulator, this behavior can only be tested on an actual device.

Properties

Name Description
Jobs

The jobs being managed by the job manager.

PreferredBackgroundStatusCheckSchedule

The preferred schedule for performing status checks while the application is in the background. This allows an application to check to see if jobs have completed and optionally post a local notification to update the user. The default value is disabled. When the value of this property is not disabled, this setting is just a preference. The operating system ultimately decides when to allow a background task to run. If you enable background status checks then you must also make sure to have enabled the "Background fetch" background mode in your application settings.

Shared

Gets the shared job manager.

StatusChecksTaskIdentifier

Gets the task identifier used for scheduling background status checks.

Methods

Name Description
Create(string)

Creates a job manager with a unique id.

PerformStatusChecks()

Check the status of all managed jobs.

ResumeAllPausedJobsAsync()

Resumes all paused jobs.

SaveState()

Saves the current job state

  • Edit this page
  • View Source
In this article
Back to top Generated by DocFX