gpt4 book ai didi

c# - BACKGROUNDTASKHOST.EXE' 已退出,代码为 1 (0x1) - 地理围栏问题

转载 作者:太空狗 更新时间:2023-10-29 21:27:33 26 4
gpt4 key购买 nike

我正在使用 GeoFence API 编写 Windows Phone 8.1 应用程序。我的问题是我无法在后台任务中触发位置更改,因为应用程序以代码 1 退出。

我已阅读有关此错误的多个主题,但没有解决方案解决我的问题。

  • 我已经检查过我的 BackgroundTask 是否是运行时组件,确实是。
  • 我已经检查了我的类(class)名称,它是正确的。
  • 我检查了我是否在我的 BackgroundTask 函数中使用了任何 await 函数,但我没有找到。
  • 我检查了我是否在应用程序 list 中注册了后台任务,是的,我注册了(使用入口点 ofc)

事实上,甚至在从 BackgroundTask 运行 Run 函数之前就会出现错误。

    namespace BackgroundTask
{
public sealed class geoFenceBackgroundTask : IBackgroundTask
{
public void Run(IBackgroundTaskInstance taskInstance)
{
ToastTemplateType toastTemplate = ToastTemplateType.ToastText02;
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);

XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
toastTextElements[0].AppendChild(toastXml.CreateTextNode("MY APP"));
toastTextElements[1].AppendChild(toastXml.CreateTextNode("Test"));

//IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
//XmlElement audio = toastXml.CreateElement("audio");

ToastNotification toast = new ToastNotification(toastXml);
ToastNotificationManager.CreateToastNotifier().Show(toast);
}
}
}

还有我的注册函数:

    async private void RegisterBackgroundTask()
{
// Get permission for a background task from the user. If the user has already answered once,
// this does nothing and the user must manually update their preference via PC Settings.
BackgroundAccessStatus backgroundAccessStatus = await BackgroundExecutionManager.RequestAccessAsync();

// Regardless of the answer, register the background task. If the user later adds this application
// to the lock screen, the background task will be ready to run.
// Create a new background task builder
BackgroundTaskBuilder geofenceTaskBuilder = new BackgroundTaskBuilder();

geofenceTaskBuilder.Name = "geoFenceBackgroundTask";
geofenceTaskBuilder.TaskEntryPoint = "BackgroundTask.geoFenceBackgroundTask";

// Create a new location trigger
var trigger = new LocationTrigger(LocationTriggerType.Geofence);

// Associate the locationi trigger with the background task builder
geofenceTaskBuilder.SetTrigger(trigger);

// If it is important that there is user presence and/or
// internet connection when OnCompleted is called
// the following could be called before calling Register()
// SystemCondition condition = new SystemCondition(SystemConditionType.UserPresent | SystemConditionType.InternetAvailable);
// geofenceTaskBuilder.AddCondition(condition);

// Register the background task

var geofenceTask = geofenceTaskBuilder.Register();
geofenceTask.Completed += (sender, args) =>
{
// MY CODE HERE

};

geofenceTask = geofenceTaskBuilder.Register();
}

我没有别的想法。有帮助吗?

最佳答案

只是偶然发现了一个类似的问题(当我通过“Lifecyle-Events-Dropdown”启动后台任务时,Visual Studio 停止了调试,并在控制台输出中声明“BACKGROUNDTASKHOST.EXE 已退出,代码为 1 (0x1)” -窗口。

在 WP8 项目中添加对我的 Tasks-Assembly (winmd) 项目的缺失引用解决了这个问题。

关于c# - BACKGROUNDTASKHOST.EXE' 已退出,代码为 1 (0x1) - 地理围栏问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25942340/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com