BACKGROUNDTASKHOST.EXE'退出了代码1(0x1) - 地理围栏问题

时间:2014-09-19 21:03:04

标签: c# windows-phone-8.1

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

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

  • 我已经检查过我的BackgroundTask是否是一个运行时组件,它是。
  • 我检查了我班级的名字,这是正确的。
  • 我已经检查过我的BackgroundTask函数中是否使用了任何await函数,但我找不到任何函数。
  • 我已经检查过我是否在应用清单中注册了背景任务,是的,我做了(带入口点)

实际上甚至在从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();            
        }

我没有其他想法。有什么帮助吗?

1 个答案:

答案 0 :(得分:7)

偶然发现了一个类似的问题(当我在#34; Lifecyle-Events-Dropdown&#34上启动后台任务时,Visual Studio停止了调试;说明" BACKGROUNDTASKHOST.EXE'已退出代码控制台输出窗口中的1(0x1)和#34;

在WP8项目中将缺少的引用添加到我的Tasks-Assembly(winmd)项目中解决了它。