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

  • SEARCH
  • Home
  • 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 7913365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:49:34+00:00 2026-06-03T13:49:34+00:00

So I have a async Web Request method with a callback: private void DoWebRequest(string

  • 0

So I have a async Web Request method with a callback:

private void DoWebRequest(string url, string titleToCheckFor, 
                          Action<MyRequestState> callback)
{
  MyRequestState result = new MyRequestState();
  // ...
  // a lot of logic and stuff, and eventually return either:
  result.DoRedirect = false;
  // or:
  result.DoRedirect = true;
  callback(result);
}

(Just to point it out up front, my WebRequest.AllowAutoRedirect is set to false for a number of reasons)

I don’t know before hand how many redirects I can expect, so I started:

private void MyWrapperCall(string url, string expectedTitle, 
                          Action<MyRequestState> callback)
{
    DoWebRequest(url, expectedTitle, new Action<MyRequestState>((a) =>
    {
      if (a.DoRedirect)
      {
        DoWebRequest(a.Redirect, expectedTitle, new Action<MyRequestState>((b) =>
        {
          if (b.DoRedirect)
          {
            DoWebRequest(b.Redirect, expectedTitle, callback);
          }
        }));
      }
    }));
}

And now I got a brain meltdown, how could I put this is in an iterative loop so it does the last callback back to the original caller if no ReDirects are needed anymore?

  • 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-03T13:49:35+00:00Added an answer on June 3, 2026 at 1:49 pm

    Store a reference to the recursing method, so it can call itself:

    private void MyWrapperCall(string url, string expectedTitle, Action<MyRequestState> callback)
    {
        Action<MyRequestState> redirectCallback = null;
        redirectCallback = new Action<MyRequestState>((state) =>
        {
            if(state.DoRedirect)
            {
                DoWebRequest(state.Redirect, expectedTitle, redirectCallback);
            }
            else
            {
                callback(state);
            }
        });
    
        DoWebRequest(url, expectedTitle, redirectCallback);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code in action script 3: async.addResponder(new Responder(result, defaultFaultHandler)); result is
I have web application Project having RPC call. one RPC async is working fine.
I have some javascript that requires a specific URL to call an ASP.NET web
I have a web method, which is called from jquery's ajax method, like this:
I have web application with WCF service. That service contains method that implements message
I'm having problem about web service method with auto increment ID. I have a
I have two async classes in my application which you can see below class
Have been reading about async and tasks and been attempting to convert the CopyFileEx
I have this sample code for async operations (copied from the interwebs) public class
I have some functionality that needs to be async in my C# app. It's

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.