知道为什么每当调用BackgrouDownloadAsync或BackgroundUploadAsync时,Lifecycle Events下都会列出一个“空”任务?
中的原始帖子答案 0 :(得分: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());
}
}