Threading help.

  • Thread starter trialproduct2004
  • Start date
T

trialproduct2004

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.
 
J

Jon Skeet [C# MVP]

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.

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.
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.

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.
 
T

Tasos Vogiatzoglou

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 ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top