0
votes

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.

1
What kind of exception is being thrown? Is your BackgroundTask a RuntimeComponent? Have you added suitable declarations in your package?Romasz
Yes For Last Two... I Couldn't Get Exception Details Even With Catch Statement... a File Named App.g.i.cs Pops up And App Crashes.user4413284
Have you added a reference to RuntimeComponent in your main project?Romasz
Yes..I have referanced to Universal Windows Runtime Component..user4413284

1 Answers

0
votes

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

enter image description here