本文整理汇总了C#中Windows.RunAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Windows.RunAsync方法的具体用法?C# Windows.RunAsync怎么用?C# Windows.RunAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows
的用法示例。
在下文中一共展示了Windows.RunAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SearchAsync
public Task<List<FlickrImage>> SearchAsync(string searchTerm, Windows.UI.Core.CoreDispatcher dispatcher)
{
return Task.Run<List<FlickrImage>>(() =>
{
var flickrImages = new List<FlickrImage>();
var photos = _Flickr.PhotosSearch(new PhotoSearchOptions(this.Username, string.Empty, TagMode.None, searchTerm));
foreach (var photo in photos)
{
dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
flickrImages.Add(new FlickrImage(null, photo.SmallUrl, photo.DoesLargeExist ? photo.LargeUrl : photo.Medium640Url, photo.Title, photo.DateTaken, photo.Description));
});
}
return flickrImages;
});
}
示例2: LoadAsync
public Task<IList<FlickrImageSet>> LoadAsync(Windows.UI.Core.CoreDispatcher dispatcher)
{
var task = Task.Run(() =>
{
var flickrUser = _GetUserProfileAsync(this.Username).Result;
var photoSetCollection = _GetPhotosetCollectionAsync(flickrUser.UserId).Result;
foreach (var photoSet in photoSetCollection)
{
FlickrImageSet imageSet = null;
dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
imageSet = new FlickrImageSet(photoSet.PhotosetSmallUrl, photoSet.Title, photoSet.DateUpdated, photoSet.Description);
this.ImageSets.Add(imageSet);
base.OnPropertyChanged("ImageSets");
}
);
var photosetPhotosCollection = _GetCollectionForSetAsync(photoSet.PhotosetId).Result;
foreach (var photo in photosetPhotosCollection)
{
dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
var image = new FlickrImage(imageSet, photo.SmallUrl, photo.DoesLargeExist ? photo.LargeUrl : photo.Medium640Url, photo.Title, photo.DateTaken, photoSet.Description);
imageSet.Collection.Add(image);
});
}
}
return this.ImageSets;
});
return task;
}
示例3: ReadAndSort
private async void ReadAndSort(Windows.UI.Core.CoreDispatcher Dispatcher)
{
//Identify that it is ID3
if (GetString(3).Equals("ID3"))
{
//Unwanted space between "ID3" tag and frame name
for (int i = 0; i < 7; i++)
data.ReadByte();
//Loop through the rest of the file, looking directly for specific frame names, reading their properties, and scrapping the rest.
while (data.UnconsumedBufferLength > 3)
{
//Use our Frame Name constant (4) to seek the identity of the tag (if it's one we care about).
//Otherwise, we loop through the bytes we don't care about.
String identity = GetString(ID3FrameNameLength);
identity = new ID3FrameDictionary().GetIdentity(identity);
//ID3 -- assuming no one took liberties extending this during encoding -- reserves 4 bytes following
//the frame name to tell decoders
byte[] byteCounter = new byte[4] { 0, 0, 0, 0 };
for (int i = 0; i < 4; i++)
{
byteCounter[i] = data.ReadByte();
}
//Since we're dealing with encoding and dealing primarily with Hex values, all values should be unsigned.
//I don't actually know is there is padding between the frame name and the value count. If there is, this following operation doesn't hurt anything
//and is set in case the 4 bytes following are all possibly used. Accounted for by 64-bit integer.
UInt64 intCounter = (ulong)((byteCounter[0] << (8 * 3)) + (byteCounter[1] << (8 * 2)) + (byteCounter[2] << (8 * 1)) + (byteCounter[3] << (8 * 0)));
//Padding of 00 00 between the 64-bit value count and the frame value. Read through the padding.
data.ReadByte();
data.ReadByte();
//Check if frame name is one we care about. (Album, Artist, Title, Cover)
if (identity != null)
{
//APIC (Album Picture) is the only frame that we could care about that can't be interpreted as a string.
if (identity.Equals("Image"))
{
//We get the byte array, but WinRT/Windows 8 makes the process of converting a byte array into a Random Access Stream difficult.
//A custom library was made for this that converts a Stream (MemoryStream) into IRandomAccessStream, so we can create a bitmap image.
MemoryStream ms = new MemoryStream(GetImage(intCounter));
MemoryRandomAccessStream randomAccessStream = new MemoryRandomAccessStream(ms);
//Create new BitmapImage inside this thread, as it isn't possible to know that this variable will come out of the UI thread operation.
BitmapImage bt = null;
//Grab UI Thread to create a new BitmapImage instance, and to take care of operations involving the UI.
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High,
async () =>
{
bt = new BitmapImage();
try
{
await bt.SetSourceAsync(randomAccessStream);
cover.Source = bt;
cover.MaxWidth = bt.PixelWidth;
cover.MaxHeight = bt.PixelHeight;
}
catch (Exception e)
{
//In case setting the source throws an exception due to corrupt extraction.
}
});
}
else
{
//Convert the bytes following the frame value count into a readable string. It skips over characters that aren't used in the English Language.
String idValue = GetString(intCounter);
fileData[identity] = idValue;
Debug.WriteLine(idValue);
}
}
else
{
//Read over the bytes we don't care about. If there is some sort of wrong interpretation of the intCounter value, the loop is broken
//so there is no attempt of reading beyond the file's length.
if (intCounter > data.UnconsumedBufferLength)
break;
for (uint i = 0; i < intCounter; i++)
data.ReadByte();
}
}
}
//We don't need this anymore. Let's dispose of it.
data.Dispose();
}