Using the thread pool properly.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i Currently have a vb.net application that iterates through a selected
directory structure. I have 6 threads running all iterating through
different folders and does an insert into sql database. The 7th thread would
start sporadically at best sometimes not at all. I would like to use the
threadpool but am not sure where to start. I am currently using this code.
Friend WithEvents df As MCS.Parser
' CREATE THREAD
Thread1 = New System.Threading.Thread(AddressOf
df.StartIndexing)
Thread1.Priority = Threading.ThreadPriority.Highest
Thread1.Start()

if i have a list of 15 directories to iterate through how do i go about
limiting it to 6 and as a thread becomes available kick off the iteration of
the next. Currently i instantiate 6 objects and 6 threads so i do the above
6 times and i don't like it. If anyone has an inkling to enlighten me and
can pull me from the pit of stupidity it would be much appreciated.

JimK
 
Jim Kitterman said:
i Currently have a vb.net application that iterates through a selected
directory structure. I have 6 threads running all iterating through
different folders and does an insert into sql database. The 7th thread
would
start sporadically at best sometimes not at all. I would like to use the
threadpool but am not sure where to start. I am currently using this
code.
Friend WithEvents df As MCS.Parser
' CREATE THREAD
Thread1 = New System.Threading.Thread(AddressOf
df.StartIndexing)
Thread1.Priority = Threading.ThreadPriority.Highest
Thread1.Start()

if i have a list of 15 directories to iterate through how do i go about
limiting it to 6 and as a thread becomes available kick off the iteration
of
the next. Currently i instantiate 6 objects and 6 threads so i do the
above
6 times and i don't like it. If anyone has an inkling to enlighten me and
can pull me from the pit of stupidity it would be much appreciated.

JimK

Why oh why do you run all of these threads with such a high priority, that
way you prevent the creating thread to even get a chance to run. Don't
change the thread priority, the task at hand is IO bound running with higher
priority than normal only disturbs the functioning of the other threads in
the whole system.

Willy.
 
Thanks for that tip, i appreciate it.

Willy Denoyette said:
Why oh why do you run all of these threads with such a high priority, that
way you prevent the creating thread to even get a chance to run. Don't
change the thread priority, the task at hand is IO bound running with higher
priority than normal only disturbs the functioning of the other threads in
the whole system.

Willy.
 
Also.... you should not use the threadpool for long running threads, are
threads really what's needed here? why not just run it all without threads,
the file system is not very good at handling multi reads even more so if its
one disk with one disk head, think of how the hardware works.

Time it, with and without the threads.

Steve
 
Back
Top