知道为什么每次调用 BackgrouDownloadAsync 或 BackgroundUploadAsync 时都会在生命周期事件下列出一个“空”任务吗?
问问题
107 次
1 回答
1
这是我替换 BackgroundDownloadAsync 和 BackgroundUploadAsync 所做的,省略了任何 try-catch 和错误检查代码。这些调用不会导致“生命周期事件”下拉列表中出现空条目。不确定它是否是由于 VS 2013 中的问题。
下载(这个比较乱,肯定有别的办法)
LiveConnectClient connectClient = new LiveConnectClient(this.Session);
LiveOperationResult _opResult = await connectClient.GetAsync(FileID + "/content");
dynamic _result = _opResult.Result;
CancellationTokenSource cts = new CancellationTokenSource();
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, new Uri(_result.location as string, UriKind.Absolute));
HttpResponseMessage response = await httpClient.SendRequestAsync(request, HttpCompletionOption.ResponseHeadersRead).AsTask(cts.Token);
using (var _stream = (await OutputFile.OpenStreamForWriteAsync()).AsOutputStream())
{
await response.Content.WriteToStreamAsync(_stream).AsTask(cts.Token);
await _stream.FlushAsync();
}
上传
LiveConnectClient connectClient = new LiveConnectClient(this.Session);
using (Stream stream = await InputFile.OpenStreamForReadAsync())
{
using (StreamReader reader = new StreamReader(stream))
{
LiveOperationResult _opResult = await connectClient.PutAsync(Awesome2FolderID + "/files/" + OneDriveFilename, reader.ReadToEnd());
}
}
于 2014-08-21T00:21:52.787 回答