c# multithread  connection timeout and excel export

Posted on 2006-06-08
Last Modified: 2009-07-29
Hello! I'm very new to C# and I'll  need your help.

I have a project in wich I must test the connection timeout to an URL , using a HTTP Request. For that i must do an asynchronous multithread to the URL(about 100 tests) and after calculate each connection timeout, I must save them in an Excel file.
Could somebody help me?
Question by:picmegamix
    1 Comment
    LVL 13

    Accepted Solution

    this should give you some ideas.  for scalability beyond there are better ways.

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Threading;

        class UrlTestResult
            public readonly bool Success;
            public readonly int Seconds;

            public UrlTestResult(bool Success, int Seconds)
                this.Success = Success;
                this.Seconds = Seconds;

        class Tester
            public delegate UrlTestResult TestUrlDelegate(string url);

            public UrlTestResult TestUrl(string url)
                //do testing here.
                return new UrlTestResult(true, 99);

            public void DoTest()
                //foreach url
                string[] urls = new string[]{""};
                UrlTestResult[] testResults = new UrlTestResult[urls.Length];
                TestUrlDelegate[] testDel = new TestUrlDelegate[urls.Length];
                IAsyncResult[] asyncResults = new IAsyncResult[urls.Length];
                WaitHandle[] waitHandles = new WaitHandle[urls.Length];

                //kick off async methods.
                for(int i = 0; i < urls.Length; i++)
                    testDel[i] = new TestUrlDelegate(this.TestUrl);
                    asyncResults[i] = testDel[i].BeginInvoke(urls[0], null, null);
                    waitHandles[i] = asyncResults[i].AsyncWaitHandle;
                //wait for all to complete.

                //now get results.
                for (int i = 0; i < urls.Length; i++)
                    testResults[i] = testDel[i].EndInvoke(asyncResults[i]);

                //do something with results
                foreach (UrlTestResult result in testResults)
                    //log to excel.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now