DataProviderDeferral 类

定义

由源应用的延迟委托用于通知 DataPackage 对象,源应用将从另一个异步函数生成数据。

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
继承
Object Platform::Object IInspectable DataProviderDeferral
属性

Windows 要求

设备系列
Windows 10 (在 10.0.10240.0 中引入)
API contract
Windows.Foundation.UniversalApiContract (在 v1.0 中引入)

示例

以下代码演示如何使用 DataProviderDeferral 对象来延迟来自目标应用的请求。

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

注解

源应用可以选择向目标应用承诺数据格式,而不是立即提供格式。 一个常见示例是,源应用支持图像格式(如 JPG),但除非目标应用请求它,否则不会创建该格式。 你可能想要下载我们的 共享内容源应用示例

方法

Complete()

通知 DataPackage 它已准备好进行处理。

适用于