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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:42:45+00:00 2026-05-26T13:42:45+00:00

First post here, sorry for starting with asking questions. In my Windows Phone 7

  • 0

First post here, sorry for starting with asking questions.

In my Windows Phone 7 app I have a working livetile that is beeing triggered by a background agent. But how can I modify the code so the httpwebrequest timeouts after 10 seconds?

Thanks in advance.

protected override void OnInvoke(ScheduledTask task)
    {
        //TODO: Add code to perform your task in background

        var request = (HttpWebRequest)WebRequest.Create(
        new Uri("site.com"));

        request.BeginGetResponse(r =>
        {
            var httpRequest = (HttpWebRequest)r.AsyncState;
            var httpResponse = (HttpWebResponse)httpRequest.EndGetResponse(r);
            using (var reader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var response = reader.ReadToEnd();

                Deployment.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    string strResult = response;


                    /// If application uses both PeriodicTask and ResourceIntensiveTask
                    if (task is PeriodicTask)
                    {
                        // Execute periodic task actions here.
                        ShellTile TileToFind = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("TileID=2"));
                        if (TileToFind != null)
                        {

                            StandardTileData NewTileData = new StandardTileData
                            {
                                BackgroundImage = new Uri("Pin-to-start.png", UriKind.Relative),
                                Title = strResult,
                                Count = null
                            };
                            TileToFind.Update(NewTileData);
                        }
                    }
                    else
                    {
                        // Execute resource-intensive task actions here.
                    }

                    NotifyComplete();
                }));
            }
        }, request);
    }
  • 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-05-26T13:42:46+00:00Added an answer on May 26, 2026 at 1:42 pm

    Here is copy/paste from code that i use in one of my apps. It will abort the connection after 60 seconds.

        private static void DoWebRequest(string uri)
        {
            string id = "my_request";
    
            Timer t = null;
            int timeout = 60; // in seconds
    
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
                request.Accept = "*/*";
                request.AllowAutoRedirect = true;
    
                // disable caching.
                request.Headers["Cache-Control"] = "no-cache";
                request.Headers["Pragma"] = "no-cache";
    
                t = new Timer(
                    state =>
                    {
                        if (string.Compare(state.ToString(), id, StringComparison.InvariantCultureIgnoreCase) == 0)
                        {
                            logger.Write("Timeout reached for connection [{0}], aborting download.", id);
    
                            request.Abort();
                            t.Dispose();
                        }
                    },
                    id,
                    timeout * 1000,
                    0);
    
                request.BeginGetResponse(
                    r =>
                    {
                        try
                        {
                            if (t != null)
                            {
                                t.Dispose();
                            }
    
                            // your code for processing the results
    
                        }
                        catch
                        {
                            // error handling.
                        }
                    },
                    request);
            }
            catch
            {
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

that's my first post here. I have problem with managing activities. I have my
This is my first post here. I have a problem. I need to take
Well, this is my first post here and really enjoying the site. I have
First post, so here goes. I'm writing a script that does intelligent search and
First post here so sorry if I seem like a newb, I am trying
First of all... Sorry for this post. I know that there are many many
Sorry folks...first post here. Just getting the hang of this site. Thanks for the
This is my first post here, and i should advise that my knowledge is
first post here so sorry for the length of it. I've been lurking and
This is the first time for me to post here, so sorry if I

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.