简体   繁体   中英

Unable To Register a Background task Windows Phone 8.1

I Need To Run Some Functions In Background In My Windows Phone 8.1 App.
I Have Created A Different Project For Background Tasks In My Solutions.
But Application Is Crashing When I Try To Register Following BG Task.
Here is My Code To Register Task`

    private async void TasksRegistration()
    {
        var taskRegistered = false;
        var TaskName = "FirstBG";

        // Checking If Task Is Already Registered..
        foreach (var task in Windows.ApplicationModel.Background.BackgroundTaskRegistration.AllTasks)
        {
            if (task.Value.Name == exampleTaskName)
            {
                taskRegistered = true;
                return;
            }
        }

        var builder = new BackgroundTaskBuilder();

        builder.Name = TaskName;
        builder.TaskEntryPoint = "BackGroundTask.FirstBG";
        builder.SetTrigger(new TimeTrigger(15, true));
        await BackgroundExecutionManager.RequestAccessAsync();
        BackgroundTaskRegistration Task = builder.Register();
    }

Application Crashed On Last Line When I Try Register This Task.
I Have Written XML Code In .Appx Manifest.

I had the exact same problem, it is most likely do to the fact that your Background Task Project is not set as a Windows Runtime Component.

Make sure the Output Type: is set to a Windows Runtime Component

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM