【发布时间】:2015-09-23 05:24:05
【问题描述】:
我正在尝试在 BackgroundTask 中的 C# W10 UWP 应用程序中将图像设置为锁屏或墙纸...在正常执行中我可以做到这一点,但是当我将相同的代码放入 @987654322 @,代码挂在StorageFile.CreateStreamedFileFromUriAsync。
// See if file exists already, if so, use it, else download it
StorageFile file = null;
try {
file = await ApplicationData.Current.LocalFolder.GetFileAsync(name);
} catch (FileNotFoundException) {
if (file == null) {
Debug.WriteLine("Existing file not found... Downloading from web");
file = await StorageFile.CreateStreamedFileFromUriAsync(name, uri, RandomAccessStreamReference.CreateFromUri(uri)); // hangs here!!
file = await file.CopyAsync(ApplicationData.Current.LocalFolder);
}
}
// Last fail-safe
if (file == null) {
Debug.WriteLine("File was null -- error finding or downloading file...");
} else {
// Now set image as wallpaper
await UserProfilePersonalizationSettings.Current.TrySetLockScreenImageAsync(file);
}
BackgroundTasks 中的StorageFile 是否有任何我不知道的限制?一些谷歌搜索没有产生这样的限制......
有什么想法吗?
谢谢。
【问题讨论】:
标签: c# stream backgroundworker background-task storagefile