DataProviderDeferral DataProviderDeferral DataProviderDeferral DataProviderDeferral Class

Definition

Used by a source app's deferral delegate to notify a DataPackage object that the source app will produce data from another asynchronous function.

public : sealed class DataProviderDeferral : IDataProviderDeferral
public sealed class DataProviderDeferral : IDataProviderDeferral
Public NotInheritable Class DataProviderDeferral Implements IDataProviderDeferral
// This class does not provide a public constructor.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Examples

The following code shows how to use a DataProviderDeferral object to defer a request from a target app.

async private void OnDeferredImageRequestedHandler(DataProviderRequest request)
{
    if (this.imageFile != null)
    {
        // A deferral object is required because this method uses "await" before setting the 
        // data in the DataPackage.
        var deferral = request.GetDeferral();

        var imageStream = await this.imageFile.OpenAsync(FileAccessMode.Read);

        // Decode the image.
        var imageDecoder = await BitmapDecoder.CreateAsync(imageStream);

        // Re-encode the image at 50% width and height.
        var inMemoryStream = new InMemoryRandomAccessStream();
        var imageEncoder = await BitmapEncoder.CreateForTranscodingAsync(inMemoryStream, imageDecoder);
        imageEncoder.BitmapTransform.ScaledWidth = (uint)(imageDecoder.OrientedPixelWidth * 0.5);
        imageEncoder.BitmapTransform.ScaledHeight = (uint)(imageDecoder.OrientedPixelHeight * 0.5);
        await imageEncoder.FlushAsync();

        request.SetData(RandomAccessStreamReference.CreateFromStream(inMemoryStream));

        await log(OutputText, "Image has been set via deferral");

        // The data is set. Signal that the operation is complete.
        deferral.Complete();
    }
    else
    {
        await log(OutputText, "Error: imageFile is null");
    }
}

Remarks

Source apps have the option of promising data formats to target apps, instead of supplying the format immediately. A common example is when a source app supports an image format, such as JPG, but doesn't create the format unless the target app requests it. To learn more about how this type of exchange works with source and target apps, see How to support pull scenarios. You might also want to download our Sharing content source app sample.

Methods

Complete() Complete() Complete() Complete()

Informs a DataPackage that it is ready for processing.

public : void Complete()
public void Complete()
Public Function Complete() As void
dataProviderDeferral.complete();

Remarks

For clipboard scenarios, your app must call Complete within 30 seconds of getting a deferral. For share scenarios, your app must call Complete within 6 minutes.

Be careful not to confuse this method with the DataRequestDeferral.Complete method that is used in share scenarios.