Delen via


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 ref class DataProviderDeferral sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class DataProviderDeferral final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class DataProviderDeferral
Public NotInheritable Class DataProviderDeferral
Inheritance
Object Platform::Object IInspectable DataProviderDeferral
Attributes

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

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. You might want to download our Sharing content source app sample.

Methods

Complete()

Informs a DataPackage that it is ready for processing.

Applies to