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 9010325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:25:36+00:00 2026-06-16T02:25:36+00:00

/* While writing this question , and testing stuff , i managed to answer

  • 0

/* While writing this question , and testing stuff , i managed to answer the question, I’m sharing my findings so they would be of help to some other poor soul. Please see answer below. */

I’m trying to fetch a JSON data from my API in a background task.
I have the background task nice and running doing it’s thing , but when i try to get the data , nothing happens ?!?

here is the code i use :

    protected override void OnInvoke(ScheduledTask task)
    {

        string wurl = @"http://test.com/api/stuff/getdata";

        WebClient webClient = new WebClient();
        webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
        webClient.DownloadStringAsync(new Uri(wurl));


        NotifyComplete();

    }

and that’s all … the webClient_DownloadStringCompleted never gets executed.

  • 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-16T02:25:37+00:00Added an answer on June 16, 2026 at 2:25 am

    The key thing here is that the WebClient executes its method asynchronously and NotifyComplete() gets executed before the WebClient has the chance to fetch the data.

    When you call NotifyComplete() , it notifies the OS that you are done executing your task and the system should terminate it.

    The solution is to move NotifyComplete() at the end of the async method webClient_DownloadStringCompleted ( in this case) and … voala !

    Warning 1: You have up to 25 seconds to finish whatever you are doing , otherwise the task gets terminated.

    Warning 2: Your background task cannot consume more than (on some phones ) 6 MB (on the emulator i tested with windows phone 8) 10 MB of memory! if your background task does , it will be terminated.

    It’s good to consider using Resource Intensive background task if your app is going to consume more memory and time ( up to 10 minutes) , note this type of task is only available while the phone is charging!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

while writing the question subject I came across some other allmost related post ...leading
I'm writing some code that looks like this: while(true) { switch(msg->state) { case MSGTYPE:
Solved while writing this question, but posting in case it helps anyone: I'm setting
I figured out what the problem was while writing this question. I post it
I've run into this while writing a Traveling Salesman program. For an inner loop,
This popped-up while writing a script for vim. Using the well-documented ':normal' command: :normal
I'm writing a cache-eject method that essentially looks like this: while ( myHashSet.Count >
While striving for const-correctness, I often find myself writing code such as this class
Writing a python program, and I came up with this error while using the
I am trying to learn and writting this part of code. while testing few

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.