我正在关注MSDN guides,在Windows Phone 8.1应用程序中注册后台任务(WindowsRunTime组件) . 到目前为止调试时我手动触发 OnSuspending 事件via Visual Studio debug toolbar lifecycle option .

当我逐步执行 OnSuspending 事件中的代码时,注册代码按预期执行,直到我到达调用 .Register() 的代码行

BackgroundTaskRegistration parkingTimerTask = taskBuilder.Register();

在进入此行后,调试器突破到 App.g.i.cs 类,并带有以下错误描述:

Parking Tag Picker WRT.exe!Parking_Tag_Picker_WRT.App.InitializeComponent.AnonymousMethod__a(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e) Line 49  C#

Question:

有谁知道如何进一步调试为什么这个注册调用失败?或者如何向输出窗口输出有关错误原因的更多信息?

我已经重新检查了我的设置,以便在我的清单中声明入口点,所有看起来都没问题 . 在我的主应用程序项目中还有对WindowsRunTime组件的引用 .

enter image description here

Code:

OnSuspending event in App.xaml.cs class:

/// <summary>
    /// Invoked when application execution is being suspended.  Application             state is saved
    /// without knowing whether the application will be terminated or resumed with the contents
    /// of memory still intact.
    /// </summary>
    /// <param name="sender">The source of the suspend request.</param>
    /// <param name="e">Details about the suspend request.</param>
    private async void OnSuspending(object sender, SuspendingEventArgs e)
    {
        var deferral = e.SuspendingOperation.GetDeferral();

        //Registration of ParkingTimer background task -->
        string myTaskName = "UpdateTimerTask";

        // check if task is already registered
        foreach (var cur in BackgroundTaskRegistration.AllTasks)
        if (cur.Value.Name == myTaskName)
        {
            //await(new MessageDialog("Task already registered")).ShowAsync();
            return;
        }

        // Windows Phone app must call this to use trigger types (see MSDN)
        await BackgroundExecutionManager.RequestAccessAsync();

        // register a new task
        BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder { Name = "Update Timer Task", TaskEntryPoint = "ParkingTimerTask.UpdateTimerTask" };
        taskBuilder.SetTrigger(new TimeTrigger(30, false));
        //Code fails at this call to register -->
        BackgroundTaskRegistration parkingTimerTask = taskBuilder.Register();

        //await(new MessageDialog("Task registered")).ShowAsync();

        // TODO: Save application state and stop any background activity
        deferral.Complete();
    }

Skeleton code of the ParkingDurationTimerTask background task to be registered:

namespace ParkingDurationTimerTask
{
    public sealed class UpdateTimerTask : IBackgroundTask
    {
        public void Run(IBackgroundTaskInstance taskInstance)
        {

        }

    }
}