c# multithread  connection timeout and excel export

Posted on 2006-06-08
Medium Priority
Last Modified: 2009-07-29
Hello! I'm very new to C# VB.net 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

devsolns earned 180 total points
ID: 16861623
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[]{"www.google.com"};
            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.

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses
Course of the Month16 days, 22 hours left to enroll

862 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