Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# BACKGROUNDTASKHOST.EXE';已退出,代码为1(0x1)-地理围栏问题_C#_Windows Phone 8.1 - Fatal编程技术网

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

C# BACKGROUNDTASKHOST.EXE';已退出,代码为1(0x1)-地理围栏问题,c#,windows-phone-8.1,C#,Windows Phone 8.1,我正在使用GeoFence API编写Windows Phone 8.1应用程序。我的问题是,我无法在后台任务中触发位置更改,因为应用程序退出时代码为1 我读过多篇关于这个错误的文章,但是没有解决我的问题的方法 我已经检查了我的BackgroundTask是否是一个运行时组件,它确实是 我已经检查了我的班名,它是正确的 我已经检查了BackgroundTask函数中是否使用了等待函数,但没有找到任何函数 我已经检查了我是否在应用程序清单中注册了后台任务,是的,我注册了(入口点为ofc) 事实

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

我读过多篇关于这个错误的文章,但是没有解决我的问题的方法

  • 我已经检查了我的BackgroundTask是否是一个运行时组件,它确实是
  • 我已经检查了我的班名,它是正确的
  • 我已经检查了BackgroundTask函数中是否使用了等待函数,但没有找到任何函数
  • 我已经检查了我是否在应用程序清单中注册了后台任务,是的,我注册了(入口点为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();            
        }

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

刚刚偶然发现了一个类似的问题(当我通过“生命周期事件下拉列表”启动后台任务时,Visual Studio停止了调试,并在控制台输出窗口中声明“BACKGROUNDTASKHOST.EXE”已退出,代码为1(0x1)”


将缺少的引用添加到WP8项目中的my Tasks Assembly(winmd)项目中解决了此问题。

您能稍微解释一下您的答案吗?我有同样的问题。我也有同样的问题。请按照此链接了解如何添加项目引用您的运行时组件必须列在Windows Phone项目的“引用”下