IBackgroundTaskInstance.GetDeferral method

Applies to Windows and Windows Phone

Informs the system that the background task might continue to perform work after the IBackgroundTask.Run method returns.

Syntax


BackgroundTaskDeferral GetDeferral()

Parameters

This method has no parameters.

Return value

Type: BackgroundTaskDeferral

A background task deferral.

Remarks

If a background task uses an asynchronous operation, it is possible for the Run method to return before the background task has completed its work. As soon as the Run method returns, the system might suspend or terminate the background task host process, which could prevent completion of asynchronous operations started by the background task.

To keep the host process from being suspended or terminated while the background task is running, use the GetDeferral method to get a background task deferral for each asynchronous operation initiated. Then, when the asynchronous operation is finished, call the BackgroundTaskDeferral.Complete method.

Be careful always to complete all obtained background task deferrals. The system does not suspend or terminate the background host process until all of its pending background task deferrals are complete. Leaving background task deferrals outstanding interferes with the system's ability to manage process lifetimes and will cause resources to leak.

Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Namespace

Windows.ApplicationModel.Background
Windows::ApplicationModel::Background [C++]

Metadata

Windows.winmd

See also

IBackgroundTaskInstance

 

 

Show:
© 2014 Microsoft