【问题标题】:The program "[2952] backgroundTaskHost.exe" has exited with the code 1 (0x1)程序“[2952] backgroundTaskHost.exe”已退出,代码为 1 (0x1)
【发布时间】:2017-06-05 23:36:25
【问题描述】:

我已经用谷歌搜索过了,但没有找到任何东西。 控制台显示:

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 Reader,但任务没有退出

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 开始时得到一个并在最后完成。如果您在任务中间调用完成,则操作系统可能会将其视为已完成并释放资源。你试过吗?
  • 哦,对不起。这只是尝试修复错误
  • 通过将它放在最后来修复它。之前是在等待声明之后,但现在在最后。谢谢

标签: c# wpf uwp windows-10-universal background-task


【解决方案1】:

我不得不把完整的标签放在最后。现在可以了

【讨论】:

    猜你喜欢
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-16
    • 1970-01-01
    • 1970-01-01
    • 2012-07-20
    相关资源
    最近更新 更多