By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,904 Members | 1,646 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,904 IT Pros & Developers. It's quick & easy.

Threading help.

P: n/a
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.

Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
<tr**************@yahoo.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2

P: n/a
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 ...

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.