Please help me implement threading 
Author Message
 Please help me implement threading

Dear sirs and madams,

I developed a class that downloads a URL's source and extracts all
links and their subsequent title and appends this data to an ArrayList
(a member of the class).

The following is a simple implementation:

class Main
{
   private ArrayList URLList
...
   void Main
   {
      URLList = new ArrayList();
      URLList = // some function that populates the list
      ...
      Scan Scanner = new Scan()

      for(int i = 0; i < URLList.Count; i+)
      {
         Scanner.Scan(URLList[i])
      }
   }
...

Quote:
}

public class Scan
{
   public ArrayList HREFs;
   public ArrayList Titles;
...
   public void Scan(string URL)
   {
       // Some function that finds all HREFs and Titles and:
       HREFs.Add(HREF);
       Titles.Add(Titles);
   }

Quote:
}

Lets say that I want 3 Scan threads to run concurrently.  How do I
start the 3 threads and know when one has finished so that another one
can startup (if the URLList.Count limit has not been reached).  How do
I make sure that threads don't populate the ArrayList at the same time
(mismatching the HREF with the Title).

I've spent the morning looking for samples that would fit the bill
here with no luck.

I appreciate any help!

Obsidience



Sat, 20 Nov 2004 03:39:06 GMT  
 Please help me implement threading
Hello Obsidience,

You can use the Asynchronous call to run the scan function in multi
threads, and use the lock keyword to synchronize the object. You can use
Asynchronous Delegate to make a call asynchronously in a new thread. For
more information about Asynchronous Delegate please see:

Asynchronous Delegates
http://msdn.microsoft.com/library/en-us/cpguide/html/cpovrasynchronou...
tes.asp

Asynchronous Delegates Programming Sample
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconasynchronou...
tesprogrammingsample.asp

To keep the consistent of the data, you can use the lock keyword to lock
the object between threads. This is the sample code:

public void Scan(string URL)
{
    // Some function that finds all HREFs and Titles and:
        lock(this)
        {
                HREFs.Add(HREF);
                Titles.Add(Titles);
        }

Quote:
}

You may get the detailed information about the lock keyword from the links
below:

http://msdn.microsoft.com/library/en-us/csref/html/vclrflockstatement...

http://msdn.microsoft.com/library/en-us/csref/html/vcwlkThreadingTuto...
p

I hope this information is helpful.

Best regards,

Lion Shi, MCSE, MCSD
Microsoft Support Engineer

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use.  2001 Microsoft Corporation. All rights
reserved.
--------------------

    Newsgroups: microsoft.public.dotnet.languages.CSharp
    Subject: Please help me implement threading
    Date: 3 Jun 2002 12:39:06 -0700
    Organization: http://groups.google.com/
    Lines: 52

    NNTP-Posting-Host: 207.12.235.25
    Content-Type: text/plain; charset=ISO-8859-1
    Content-Transfer-Encoding: 8bit
    X-Trace: posting.google.com 1023133146 26242 127.0.0.1 (3 Jun 2002
19:39:06 GMT)

    NNTP-Posting-Date: 3 Jun 2002 19:39:06 GMT
    Path:
cpmsftngxa07!tkmsftngxs01!tkmsftngxs02!tkmsftngp01!newsfeed00.sul.t-online.d
e!t-online.de!newsfeed.icl.net!isdnet!sn-xit-02!supernews.com!postnews1.goog
le.com!not-for-mail
    Xref: cpmsftngxa07 microsoft.public.dotnet.languages.csharp:65469
    X-Tomcat-NG: microsoft.public.dotnet.languages.csharp

    Dear sirs and madams,

    I developed a class that downloads a URL's source and extracts all
    links and their subsequent title and appends this data to an ArrayList
    (a member of the class).

    The following is a simple implementation:

    class Main
    {
       private ArrayList URLList
    ...
       void Main
       {
          URLList = new ArrayList();
          URLList = // some function that populates the list
          ...
          Scan Scanner = new Scan()

          for(int i = 0; i < URLList.Count; i+)
          {
             Scanner.Scan(URLList[i])
          }
       }
    ...
    }

    public class Scan
    {
       public ArrayList HREFs;
       public ArrayList Titles;
    ...
       public void Scan(string URL)
       {
           // Some function that finds all HREFs and Titles and:
           HREFs.Add(HREF);
           Titles.Add(Titles);
       }
    }

    Lets say that I want 3 Scan threads to run concurrently.  How do I
    start the 3 threads and know when one has finished so that another one
    can startup (if the URLList.Count limit has not been reached).  How do
    I make sure that threads don't populate the ArrayList at the same time
    (mismatching the HREF with the Title).

    I've spent the morning looking for samples that would fit the bill
    here with no luck.

    I appreciate any help!

    Obsidience



Sun, 21 Nov 2004 14:04:06 GMT  
 Please help me implement threading
I'll take a look - thanks for your help!

Obsidience

Quote:

> Hello Obsidience,

> You can use the Asynchronous call to run the scan function in multi
> threads, and use the lock keyword to synchronize the object. You can use
> Asynchronous Delegate to make a call asynchronously in a new thread. For
> more information about Asynchronous Delegate please see:

> Asynchronous Delegates
> http://msdn.microsoft.com/library/en-us/cpguide/html/cpovrasynchronou...
> tes.asp

> Asynchronous Delegates Programming Sample
> http://msdn.microsoft.com/library/en-us/cpguide/html/cpconasynchronou...
> tesprogrammingsample.asp

> To keep the consistent of the data, you can use the lock keyword to lock
> the object between threads. This is the sample code:



Mon, 22 Nov 2004 23:58:26 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!

2. Please help!!!!Please help!!!!Please help!!!!

3. HELP: Implementing MFC strategy PLEASE!

4. The Thread that wont die. - Please Help

5. freeing handles, GC, and threading .... please help

6. SunOS threads - PLEASE HELP

7. Please Help - Adding Controls to a form from a child thread

8. Please help me to choose a threading model

9. Help Please - Identifying Process Threads

10. Timers , Threads or what?? Please Help, its urgent

11. Thread/CreateProcess Help Please !

12. How to write threads in C-help please to siva

 

 
Powered by phpBB® Forum Software