所以我决定在这里写下我自己的答案,因为我不确定其他人是否会解决这个问题。我怀疑的一件事是我最近将 C# 语言更新到了 v7.3,因为 VS 2017 在编写一些代码时是这样说的。也许问题与此有关,但到目前为止我的解决方案在最小化状态下工作。
我还想在此声明,我BackgroundTask首先实施以ApplicationTrigger在需要时触发该过程来克服这个问题,但老实说这是一种黑客攻击。看一下代码:
public static async Task<string> GetBackgroundTaskReturnValue(string apiRequestUrl)
{
StaticItemsHelper.IsBackgroundPlaylistTaskRunning = true;
if (StaticItemsHelper.IsBackgroundPlaylistTaskRunning)
{
for (int seconds = 0; seconds < 20;)
{
if (!StaticItemsHelper.IsBackgroundPlaylistTaskRunning)
{
break;
}
else
{
Task.Delay(1000).Wait();
}
}
}
var request = BackgroundTaskHelper.BackgroundPlaylistTrigger.RequestAsync().GetResults();
if (request == Windows.ApplicationModel.Background.ApplicationTriggerResult.Allowed)
{
SettingsHelper.localSettings.Values[SettingsHelper.BackgroundPlaylistPlaybackURLKey] = apiRequestUrl;
SettingsHelper.localSettings.Values[SettingsHelper.BackgroundPlaylistPlaybackTokenKey] = StaticItemsHelper.CurrentUserAccessToken;
if (SettingsHelper.tempFolder.TryGetItemAsync(SettingsHelper.BackgroundPlaylistPlaybackReturnKey).GetResults() is StorageFile file)
{
await file.DeleteAsync();
}
for (int seconds = 0; seconds < 30;)
{
if (SettingsHelper.tempFolder.TryGetItemAsync(SettingsHelper.BackgroundPlaylistPlaybackReturnKey).GetResults() is StorageFile _rfile)
{
守着一只汪
相关分类