我正在尝试在我的 C# W10 UWP 应用程序中将图像设置为锁屏或墙纸BackgroundTask
......我可以在正常执行中很好地做到这一点,但是当我将相同的代码放入 aBackgroundTask
时,代码会挂在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);
}
有什么我不知道的StorageFile
限制吗?BackgroundTasks
一些谷歌搜索没有产生这样的限制......
有任何想法吗?
谢谢。