Groups | Blog | Home
all groups > c# > october 2005 >

c# : Threading help.


trialproduct2004 NO[at]SPAM yahoo.com
10/5/2005 11:07:16 PM
Hi all,
i am having c# application.
I have bunch of URL's which i want to validate.
that means i want to check whether those url's are valid or not.
When i start processing url's one by on synchronysly its taking lots of
time.
So what i want is to split above task.
I want to use threading in this case to make process faster.
I want to created threads which are processing say 5 urls at a time.
Like that i want to create some threads which are validating url's.
is it correct way to make process faster.

And one more question.
Can i change thread procedure of thread without creating new thread.
Like say suppose i have one thread for which i have assigned some
thread procedure.
After that thread procedure is over i want to use same thread object to
reassign some other thread procedure.
Can i do it.
Any help will be appreciated.
Tasos Vogiatzoglou
10/5/2005 11:31:26 PM
Creating a thread involves the following steps :

1) Creating a ThreadStart delegate to specify the code that you want to
run as a thread. Keep in mind that this does not support parameters, so
if you want to pass some data to your thread you have to create a class
that will hold the method and the parameters.

2) Creating a Thread class with the ThreadStart that you created above
as a parameter.

Apparently the use of threads in your example is pretty normal as long
as you pay attention to things like synchronization issues and objects
locking.

Now... for your second question... no you cant.

Refs :
ms-help://MS.MSDNQTR.2005APR.1033/cpguide/html/cpconthreadsthreading.htm
ms-help://MS.MSDNQTR.2005APR.1033/cpref/html/frlrfSystemThreadingThreadClassTopic.htm
ms-help://MS.MSDNQTR.2005APR.1033/cpguide/html/cpconCollectionsSynchronizationThreadSafety.htm
ms-help://MS.MSDNQTR.2005APR.1033/cpguide/html/cpconThreadPooling.htm

Have a nice day ...
Jon Skeet [C# MVP]
10/6/2005 7:26:11 AM
[quoted text, click to view]

Well, an alternative would be to use asynchronous calls with
WebRequest. Using new threads would work though. Bear in mind that if
you have lots of URLs to the same host, .NET will (by default) limit
how many simultaneous connections you can make to that machine.

[quoted text, click to view]

That's the job of a thread pool. I don't recommend using the system
thread pool as it can lead to deadlock very easily. See
http://www.pobox.com/~skeet/csharp/miscutil for a free custom thread
pool.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
AddThis Social Bookmark Button