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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:29:35+00:00 2026-05-28T03:29:35+00:00

I have to create mutiple web request to same URL using webclient. I spawn

  • 0

I have to create mutiple web request to same URL using webclient. I spawn thread using thread pool QueueUserWorkItem. Code below show how I am spawning thread and posting using WebClient. I had to derive web client class to set Expect100Continue and Timeout property.

When I run this code without Thread.Sleep (commented line in spawn thread code), I am getting response time over 1500 millisecond. Please check the logic to calculate response time in PostToURL method. But If I put 1 seconds sleep before spawning another thread, I am getting response time less than 300 milliseconds. I could not find reason why is that so different. Actually I need to bring this response time to 300 millisecond. This is test harness code that I am writing to test a service. Can you point why is different response time?

Here is the code that spawns the thread

foreach (var nameValueCollection in requestCollections)
{
    NameValueCollection collection = nameValueCollection;
    ThreadPool.QueueUserWorkItem(a => { if (collection != null) PostToURL    
    (collection); });
    //Thread.Sleep(TimeSpan.FromSeconds(1));
 }

Here is method that post to a URL

public void PostToURL(NameValueCollection collection)
    {
        DateTime requestStartDate = DateTime.Now;
        DateTime requestEndDate = DateTime.Now;
        string encodedResponse;
        try
        {
            using (var transportType2 = new DerivedWebClient())
            {
                transportType2.Expect100Continue = false;
                transportType2.Timeout = TimeSpan.FromMilliseconds(2000);

                ServicePointManager.ServerCertificateValidationCallback =
                    new RemoteCertificateValidationCallback(delegate { return true; });

                requestStartDate = DateTime.Now;
                var responseArray = transportType2.UploadValues("http://xyz/Post.ashx?AccountName=myaccount",
                                                                "POST", collection);
                requestEndDate = DateTime.Now;
                Console.WriteLine(requestEndDate.Subtract(requestStartDate).TotalMilliseconds);

                encodedResponse = Encoding.ASCII.GetString(responseArray);

                transportType2.Dispose();
            }
        }
        catch (Exception exception)
        {
            requestEndDate = DateTime.Now;
            encodedResponse = exception.ToString();
        }

        //Global variable to record request and response
        responses.Add(new ServiceResponse
        {
            ResponseInMs = (int) requestEndDate.Subtract(requestStartDate).TotalMilliseconds,
            StartTime = requestStartDate,
            EndTime = requestEndDate,
            Response = encodedResponse,
            Request = string.Join(";", collection.Cast<string>()
                        .Select(col => String.Concat(col, "=", collection[col])).ToArray()),
            ApplicationId = collection["ApplicationId"]

        });
    }

UPDATED
Here is code that derive webclient

public class DerivedWebClient: WebClient
{
    public bool Expect100Continue
    {
        get;
        set;
    }

    public TimeSpan Timeout
    {
        get;
        set;
    }

    protected override WebRequest GetWebRequest(Uri address)
    {
        var request = (HttpWebRequest)base.GetWebRequest(address);
        if (request != null)
        {
            request.ServicePoint.Expect100Continue = Expect100Continue;
            request.KeepAlive = false;
            request.Timeout = (int) Timeout.TotalMilliseconds;
        }

        return 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-28T03:29:35+00:00Added an answer on May 28, 2026 at 3:29 am

    This question may be duplicate to UploadValuesAsync response time. But the code blocks are different I would consider different questions but the problem are same. Answer to the other question also, applies here.

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

Sidebar

Related Questions

I am using AS3 to create a tween affect between multiple images that have
i have create a form (so it's PHP and HTML hybrid-code). it has ability
I have multiple views which make the same NSURLRequest/NSURLConnection request . Ideally, in order
Suppose I have the following (rather common) model Client invokes web service request ->
Here is my situation. I have a web page for users to create their
We have a web app in which a request for a long running or
I have a console app that makes a single request to a web page
I'm using a hibernate session per request model for my web application. My jdbc
In my current web application, I have to create a Reputation Points & Badges
I have to code a web portal that offers multiple and varied features such

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.