0
我已經對它進行了GOOGLE搜索,但沒有發現任何內容。 該控制檯顯示:程序「[2952] backgroundTaskHost.exe」已退出,並顯示代碼1(0x1)
The program "[2952] backgroundTaskHost.exe" has exited with the code 1 (0x1)
的MainProject得到了參考Backgroundtask。任務在等待fileIO讀取器時退出。
StorageFile sampleFile = await storageFolder.GetFileAsync("Klasse.txt");
Stufe = await FileIO.ReadTextAsync(sampleFile);
之前,我已經叫另一FileIO專注閱讀器,但任務沒有退出
StorageFile sampleFile = await storageFolder.GetFileAsync("Facher.txt");
Fach = await FileIO.ReadTextAsync(sampleFile);
總而言之:
namespace BackgroundTask
{
public sealed class BackgroundTask : IBackgroundTask
{
string Stufe = "";
string Fach = "";
BackgroundTaskDeferral _deferral;
public async void Run(IBackgroundTaskInstance taskInstance)
{
_deferral = taskInstance.GetDeferral();
StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
//GetFächer
try
{
StorageFile sampleFile = await storageFolder.GetFileAsync("Facher.txt");
Fach = await FileIO.ReadTextAsync(sampleFile);
}
catch (Exception e) { }
//GetStufe
try
{
StorageFile sampleFile = await storageFolder.GetFileAsync("Klasse.txt");
Stufe = await FileIO.ReadTextAsync(sampleFile);
}
catch (Exception e) { Debug.WriteLine(e); }
_deferral.Complete();
[...]
}
}
爲什麼你得到多個延期?我認爲你應該在* Run *開始之後得到一個,並在最後完成。如果您在任務中間調用complete,可能OS會將其視爲已完成並釋放資源。你嘗試過嗎? – Romasz
哦,斯里。這只是一個嘗試修復錯誤 –
通過把它放在最後。之前是在等待聲明之後,但現在在最後。謝謝 –