DataProviderDeferral DataProviderDeferral DataProviderDeferral DataProviderDeferral Class

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

Syntax

Declaration

public sealed class DataProviderDeferralpublic sealed class DataProviderDeferralPublic NotInheritable Class DataProviderDeferralpublic sealed class DataProviderDeferral

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.

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");
    }
}

Methods summary

Informs a DataPackage that it is ready for processing.

Methods

  • Complete()
    Complete()
    Complete()
    Complete()

    Informs a DataPackage that it is ready for processing.

    public void Complete()public void Complete()Public Function Complete() As voidpublic void 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 Complete() method that is used in share scenarios.

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.DualApiPartitionAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute

Details

Assembly

Windows.ApplicationModel.DataTransfer.dll