Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8790285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:36:42+00:00 2026-06-13T22:36:42+00:00

Client.GetAsync appears to fail for me when running in a background task in my

  • 0

Client.GetAsync appears to fail for me when running in a background task in my Windows 8 Metro app.

I tried using both a TimeTrigger and a MaintenanceTrigger. It appears that there is no exception. When debugging it, it just exits at that line (if I keep pressing step over), even though there is way more to execute as well as a try-catch around it.

This leads me to believe that Windows is cancelling my task. So I listened to the cancelled event with no luck.

I have declared Internet access as a capability, and the task has been properly registered. Furthermore, my app has full lock screen access.

What am I doing wrong?

Here’s the code I use to register the background task currently.

if (await ObtainLockScreenAccess())
{
    const string name = "Task";

    var updaterTasks = BackgroundTaskRegistration.AllTasks.Where(t => t.Value.Name == name);
    if (!updaterTasks.Any())
    {

        var builder = new BackgroundTaskBuilder();
        builder.Name = name;
        builder.TaskEntryPoint = "Stackstabilizer.BackgroundTasks.UpdateBackgroundTask";

        var trigger = new MaintenanceTrigger(15, false);
        var condition = new SystemCondition(SystemConditionType.InternetAvailable);

        builder.AddCondition(condition);
        builder.SetTrigger(trigger);

        var task = builder.Register();

        Debug.WriteLine("Task has been registered");

    }
}

Edit Here’s the background task signature:

namespace Stackstabilizer.BackgroundTasks
{
    // You must use a sealed class, and make sure the output is a WINMD. 
    public sealed class UpdateBackgroundTask : IBackgroundTask
    {
        public async void Run(IBackgroundTaskInstance taskInstance)
        {

            var deferral = taskInstance.GetDeferral();

            try { ... } finally { deferral.Complete(); }

        }
     }

}

And here’s some details on my declarations.

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:36:43+00:00Added an answer on June 13, 2026 at 10:36 pm

    I had a similar problem to you before, and the way I solved it was to have another deferral in the async task. I think the idea is that, whenever you have an async task, you need a deferral. (I’m not sure if it’s best practice, but hey, it works)

    Code:

        public void Run(IBackgroundTaskInstance taskInstance)
        {
            updateAllTiles(taskInstance);
        }
    
    
        public async void updateAllTiles(IBackgroundTaskInstance taskInstance)
        {
            // Need to use a deferral to run async tasks in the background task
            BackgroundTaskDeferral deferral = taskInstance.GetDeferral();
    
            dosomething(taskInstance);
    
            deferral.Complete();
        }
    
        private async void dosomething(IBackgroundTaskInstance taskInstance)
        {
            BackgroundTaskDeferral deferral = taskInstance.GetDeferral();
    
            HttpClient client = new HttpClient();
            HttpResponseMessage resp = await client.GetAsync(new Uri(url));
    
            updateTile(resp);
    
            deferral.Complete();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Client side form validation becomes easiest by using jQuery. I tried all validators and
I'm using HttpClient in a Windows 8 app and it seems that it purposely
I'm using this code to download a web page in my Metro Style app:
I have a Win RT app that has a background task responsible for calling
Client wants a button on the mobile web app that launches a QR code
Client + Server are both written in Javascript. I don't have a master game
I'm using HttpClient 0.6.0 from NuGet. I have the following C# code: var client
Client: string value = <?xml version=1.0?><person><firstname>john</firstname><lastname>smith</lastname> <person/>; using (HttpResponseMessage response = m_RestHttpClient.Post(new/customerxml/+value2, frm.CreateHttpContent())) {
A client has asked for additional security for a web app which would allow
Possible Duplicate: JsonArray.Parse(…) error I am developing a manga information app for Windows 8

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.