长期运行的股票 [英] Long running shares

查看:91
本文介绍了长期运行的股票的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

根据
MSDN文档
,如果我想在共享请求中执行异步操作,我需要获得e
推迟对象并调用其完整方法来通知异步共享的数据内容已准备就绪。

According to MSDN documentation, if I want to perform an asynchronous operation within a share request, I need to obtain e Deferral object and call its Complete method to notify that data content for the asynchronous share is ready.

特别是在备注部分中写得:

In particular, in the Remarks section it is written that:

此函数必须在200ms内返回 DataPackage 对象以防止超时操作。如果您的应用程序共享需要更多时间打包的内容,例如文件或照片集合,请不要使用此
方法。相反,请使用
SetDataProvider 将委托分配给
DataPackage 并将 DataPackage 返回目标应用。

This function must return a DataPackage object within 200ms to prevent the operation from timing out. If your app shares content that takes more time to package, such as a collection of files or photos, don't use this method. Instead, use the SetDataProvider method to assign a delegate to a DataPackage and return that DataPackage to the target app.

所以,我有尝试了以下代码:

So, I have tried the following code:

private async void DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
{
    var request = e.Request;
    var deferral = request.GetDeferral();

    // Long running operations ...
    HttpClient client = new HttpClient();
    var bytes = await client.GetByteArrayAsync("http://www.carto.net/neumann/panoramas/sandnes_flakstadoya_lofoten_2008_06/pano1/sandnes_flakstadoya_lofoten_panorama_medium_res.jpg");

    var stream = new InMemoryRandomAccessStream();
    var writer = new DataWriter(stream.GetOutputStreamAt(0));
    writer.WriteBytes(bytes);
    
    await writer.StoreAsync();
    await writer.FlushAsync();

    request.Data.Properties.Title = "Share Example";
    request.Data.Properties.Description = "Share with long running async operation.";
    request.Data.SetUri(new Uri("http://www.carto.net/neumann/panoramas/sandnes_flakstadoya_lofoten_2008_06/pano1/sandnes_flakstadoya_lofoten_panorama_medium_res.jpg"));
    request.Data.SetBitmap(RandomAccessStreamReference.CreateFromStream(stream));

    deferral.Complete();
}

下载图像并将其作为共享内容提供需要超过200毫秒,但一切正常并且我能够完成共享任务超时。

Downloading the image and providing it as share content requires more than 200 milliseconds, but everything works fine and I'm able to complete the share task with no time out.

事实上, e.Request.Deadline 属性,根据文档获取完成延迟渲染操作的截止日期,在我的情况下 表示约49天。

Infact, the e.Request.Deadline property, that according to the documentation gets the deadline for finishing a delayed rendering operation, in my case indicates about 49 days.

那么,200毫秒的时间限制何时适用?

So, when does the 200 milliseconds time limit apply?

提前致谢。

Marco Minerva [MCPD]

博客: http:/ /marcominerva.wordpress.com

Twitter: @marcominerva

Marco Minerva [MCPD]
Blog: http://marcominerva.wordpress.com
Twitter: @marcominerva

推荐答案

我不确定这是什么意思"截止日期",这是一个DateTimeOffset,而不是绝对值。是
总是 49?

I'm not sure that's what they mean by "deadline", which is a DateTimeOffset, not an absolute value. Is it always 49?

MS推荐的模式是只移动正在加载的代码图像成为代表。它没有增加太多的复杂性,我认为它是最安全的,特别是因为你从网上加载。

The pattern MS is recommending here is to just move the code that's loading the image into a delegate. It doesn't add much complexity and I think it's safest, particularly since you're loading from the Web.


这篇关于长期运行的股票的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆