Click here to Skip to main content
13,404,383 members (45,861 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I have a lab exercise. I do not understand urls.length and waitHandles.waitAll in this exercise.

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

namespace LabEx1
    class Program
        static void Main(string[] args)
            AutoResetEvent[] waitHandles = new AutoResetEvent[urls.length];

            int i = 0;
            foreach (string url in urls)
                waitHandles[i] = new AutoResetEvent(false);
                ThreadInfo ti = new ThreadInfo(url, waitHandles[i]);
                ThreadPool.QueueUserWorkItem(getPage, ti);

        class ThreadInfo
            public string url;
            public AutoResetEvent are;

            public ThreadInfo(string _url, AutoResetEvent _are)
                url = _url;
                are = _are;
            static void getPage(object data)
                ThreadInfo ti = (ThreadInfo)data;
                WebResponse wr = WebRequest.Create(ti.url).GetResponse();
                Console.WriteLine(ti.url + ": " + wr.Headers["Content-Length"]);
Posted 19-Mar-12 2:23am
Updated 19-Mar-12 2:38am
BobJanova 19-Mar-12 7:46am
Did you write this code? And if so, how did you write it without understanding those things?
SAKryukov 19-Mar-12 21:12pm
Oshtri Deka 19-Mar-12 8:22am
This code has too many errors.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Isn't google available where you are? Try googling "AutoResetEvent" and see what it tells you.

As far as the urls.Length issue is concerned, urls appears to be an array of strings, and it's passing the length of that array into AutoRresetEvent. Of course, if you had researched AutoResetEvent, you'd know why it's passing the length of the array as a parameter.
Shahin Khorshidnia 19-Mar-12 18:37pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

check this link out.[^]

In a nutshell AutoResetEvent notifies a waiting thread that an event has occurred.

Waits for all the elements in the specified array to receive a signal[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.1802120.2 | Last Updated 19 Mar 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100