help regarding Threading

  • Thread starter Thread starter trialproduct2004
  • Start date Start date
T

trialproduct2004

Hi all
i am having application in C#.
here what i want it to update one datagrid depending on particular
value.
I want to start minimum of 5 threads at a time and all these threads
are updating datagrid in their thread proceudre.
What i want is whenever 5 threads are running as soon as one thread
finish its execution i want to asssing new thread proceudre to that
thread.
Can some one tell me how to do it?
Any help will be appreciated.
thanks in advance.
 
Hi,

First of all, bear in mind that any updates to UI controls are possible only
from the UI thread. You can run 5 monitoring threads, but you will have to
use the Control.Invoke method to perform any UI updates on the UI thread
from a worker one.

If you want to assign different thread procedures, you might be better off
using asynchronous delegates. But, the overall design looks somewhat
cumbersome to me. Would you please elaborate on what is your high-level task
so that the community might come up with a more appropriate solution?
 
Hi
thanks for your reply.
Actually my problem is i am having one function which is downloading
data from net using web request.
I want my application to start more than 1 downloads at a time. and i
don't want to use asynchrousoy access to web request i want to do it
through threading.
Like suppose my first thread is downloading one url and second thread
is downloading second url.
so what i want is, whenever either first or second thread completes its
execute i want to start downloading next url from list.
this is my problem.
can u help me.
Or if u want u can give me other solution to do this.
any help will be appreciated.
thanks in advnace.
 
Hi,

Take a look at this article

http://msdn.microsoft.com/library/d...n-us/dnwinforms/html/datagridcolumnstyle2.asp

It has nothing to do with the threads but with the grid.

Regarding the threading you could create a data class that containing , url
and reference to the progressbar in the grid. Then using a Sync queue you
add to it all the urls you want to download.
Then you create your five threads and each thread Pop from the queue and
start the download. You have to decide what to do with the thread if nothing
is waiting to be downloaded .



cheers,
 
i am having application in C#.
here what i want it to update one datagrid depending on particular
value.
I want to start minimum of 5 threads at a time and all these threads
are updating datagrid in their thread proceudre.

Okay, that's a mistake to start with.

See http://www.pobox.com/~skeet/csharp/threads/winforms.shtml
What i want is whenever 5 threads are running as soon as one thread
finish its execution i want to asssing new thread proceudre to that
thread.

That's basically thread-pooling, or a producer-consumer queue,
depending on your exact situation.

See http://www.pobox.com/~skeet/csharp/miscutil for a free threadpool,
or http://www.pobox.com/~skeet/csharp/threads/deadlocks.shtml for a
producer/consumer queue example (about half way down).
 
Back
Top