的Windows Phone 8.1后台任务 - 无法调试,将不火 [英] Windows Phone 8.1 Background Task - Can't Debug and won't fire
问题描述
林具有在WP8.1的后台任务一个问题 我创建了一个后台任务作为Windows运行时组件下面这个教程: http://msdn.microsoft.com/en-us /library/windows/apps/xaml/hh977055.aspx
Im having a issue with the Background Tasks in WP8.1 I have created a background task as a windows runtime component following this tutorial : http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh977055.aspx
现在的问题是,我不能让我的后台任务运行。它运行onNetworkChange。我什么时候才能到飞行模式,并支持它不点火。当我去到生命周期事件的调试位置工具,它说没有任何后台任务。我已经调试了code,它注册后台任务,它是得到注册。我也越来越这断点将目前尚未受到打击。无符号已加载这个文件我认为这是造成问题的原因。
The problem is, i can't get my background task to run. It runs onNetworkChange. When i can to flight mode and back it is not firing. When i go to lifecycle events in the Debug Location toolbar it says No Background tasks. I have debugged the code that registers the background task and it is getting registered. I am also getting 'This breakpoint will not currently be hit. No symbols have been loaded for this document' which i think is causing the problem.
我已经试过 - 删除bin和OBJ文件夹和重建。 - 清洗该项目。 - 试图从头开始构建项目。 - 将只是我的code选项关闭。 - 试图做同样的事情在另一台机器,仍然一无所获。
I have tried - deleting the bin and obj folder and rebuilding. - cleaning the project. - trying to build the project from scratch. - turning Just my code option off. - tried doing the same thing on another machine, still nothing.
我的code登记
var taskRegistered = false;
var exampleTaskName = "UploadTask";
foreach (var task in BackgroundTaskRegistration.AllTasks)
{
if (task.Value.Name == exampleTaskName)
{
taskRegistered = true;
break;
}
}
if (!taskRegistered)
{
var builder = new BackgroundTaskBuilder();
builder.Name = exampleTaskName;
builder.TaskEntryPoint = "Tasks.Upload";
builder.SetTrigger(new SystemTrigger(SystemTriggerType.NetworkStateChange, false));
BackgroundTaskRegistration task = builder.Register();
}
包清单文件如下:
package manifest file is as follows
<Extensions>
<Extension Category="windows.backgroundTasks" EntryPoint="Tasks.Upload">
<BackgroundTasks>
<Task Type="systemEvent" />
<m2:Task Type="deviceUse" />
</BackgroundTasks>
</Extension>
</Extensions>
我的任务是这样的:
My task looks like this :
namespace Tasks
{
public sealed class Upload : IBackgroundTask
{
public void Run(IBackgroundTaskInstance taskInstance)
{
Debug.WriteLine("Am i even getting here?");
}
}
}
谁能帮助,因为我已经花了很多时间让这个工作。谢谢
Can anyone help as i've spent far too long getting this to work. Thanks
推荐答案
当我想你的code,有一个与这个特定的<一个个问题href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.applicationmodel.background.systemtriggertype.aspx"相对=nofollow> SystemTriggerType.NetworkStateChange - 事实上,我也没有看到注册的 BackgroundTask 的中的生命周期事件的下拉列表。但是,如果我只能改变的 SystemTriggerType 的如来的 SystemTriggerType.TimeZoneChange 的那么我就能看到它。
As I've tried your code, there is a problem with this specific SystemTriggerType.NetworkStateChange - indeed I also don't see the registered BackgroundTask in Lifecycle Events dropdown. But if I only change the SystemTriggerType for example to SystemTriggerType.TimeZoneChange then I'm able to see it.
下面是code修改了一点:
Here is the code modified a little:
await BackgroundExecutionManager.RequestAccessAsync();
if (!taskRegistered)
{
Debug.WriteLine("Registering task inside");
var builder = new BackgroundTaskBuilder();
builder.Name = exampleTaskName;
builder.TaskEntryPoint = "Tasks.Upload";
builder.SetTrigger(new SystemTrigger(SystemTriggerType.TimeZoneChange, false));
BackgroundTaskRegistration task = builder.Register();
await new MessageDialog("Task registered!").ShowAsync();
}
我不知道为什么用C原来的$ C $的 BackgroundTask 的是不是VS可见,尽管它正在注册 - 它在的 BackgroundTaskRegistration.AllTasks 的 - 在这种情况下,也许尝试与调试不同的 SystemTriggerType 的和SWICH到所需的一个与发行版本。
I'm not sure why with the original code the BackgroundTask is not visible in VS, though it is being registered - it's in BackgroundTaskRegistration.AllTasks - in this case maybe try to debug with different SystemTriggerType and swich to desired one with release version.
我还测试了如果的 BackgroundTask 的有问题的的 SystemTriggerType.NetworkStateChange 的工作 - 实际上 - 它的正在。我已经修改了的 BackgroundTask 的一点点发送敬酒消息时的 NetworkState 的变化。注册任务,当我打开/ WiFi的关后,我得到一个敬酒messgae。在code的任务:
I've also tested if the BackgroundTask with the problematic SystemTriggerType.NetworkStateChange works - and indeed - it is working. I've modified your BackgroundTask a little to send a toast message when NetworkState changes. After registering the task, when I turn the WiFi on/off, I get a toast messgae. The code for the task:
public sealed class Upload : IBackgroundTask
{
public void Run(IBackgroundTaskInstance taskInstance)
{
Debug.WriteLine("Hello Pat");
ToastTemplateType toastTemplate = ToastTemplateType.ToastText02;
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
XmlNodeList textElements = toastXml.GetElementsByTagName("text");
textElements[0].AppendChild(toastXml.CreateTextNode("Upload Task - Yeah"));
textElements[1].AppendChild(toastXml.CreateTextNode("I'm message from your Upload task!"));
ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(toastXml));
}
}
完整的例子,你可以在这里下载。
这篇关于的Windows Phone 8.1后台任务 - 无法调试,将不火的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!