本文整理汇总了C#中IAsyncOperation.AsTask方法的典型用法代码示例。如果您正苦于以下问题:C# IAsyncOperation.AsTask方法的具体用法?C# IAsyncOperation.AsTask怎么用?C# IAsyncOperation.AsTask使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAsyncOperation
的用法示例。
在下文中一共展示了IAsyncOperation.AsTask方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AsyncOperationBitmapProvider
public AsyncOperationBitmapProvider(IAsyncOperation<Bitmap> bitmapAsyncOperation)
{
m_bitmapAsyncOperation = bitmapAsyncOperation
.AsTask()
.ContinueWith(t => (IReadableBitmap)t.Result, TaskContinuationOptions.OnlyOnRanToCompletion|TaskContinuationOptions.ExecuteSynchronously)
.AsAsyncOperation();
}
示例2: ExecuteChannelOperation
private IAsyncOperation<ChannelAndWebResponse> ExecuteChannelOperation(IAsyncOperation<PushNotificationChannel> channelOperation, String url, String itemId, bool isPrimaryTile)
{
return channelOperation.AsTask().ContinueWith<ChannelAndWebResponse>((Task<PushNotificationChannel> channelTask) =>
{
PushNotificationChannel newChannel = channelTask.Result;
String webResponse = "URI already uploaded";
// Upload the channel URI if the client hasn't recorded sending the same uri to the server
UrlData dataForItem = TryGetUrlData(itemId);
if (dataForItem == null || newChannel.Uri != dataForItem.ChannelUri)
{
HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(url);
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
byte[] channelUriInBytes = Encoding.UTF8.GetBytes("ChannelUri=" + WebUtility.UrlEncode(newChannel.Uri) + "&ItemId=" + WebUtility.UrlEncode(itemId));
Task<Stream> requestTask = webRequest.GetRequestStreamAsync();
using (Stream requestStream = requestTask.Result)
{
requestStream.Write(channelUriInBytes, 0, channelUriInBytes.Length);
}
Task<WebResponse> responseTask = webRequest.GetResponseAsync();
using (StreamReader requestReader = new StreamReader(responseTask.Result.GetResponseStream()))
{
webResponse = requestReader.ReadToEnd();
}
}
// Only update the data on the client if uploading the channel URI succeeds.
// If it fails, you may considered setting another AC task, trying again, etc.
// OpenChannelAndUploadAsync will throw an exception if upload fails
UpdateUrl(url, newChannel.Uri, itemId, isPrimaryTile);
return new ChannelAndWebResponse { Channel = newChannel, WebResponse = webResponse };
}).AsAsyncOperation();
}