Home All Groups Group Topic Archive Search About
Author
22 Jan 2006 10:38 PM
Hugh Janus
Hi all,

I know this has been discussed a million times here but either I am not
finding the right information yet or I just do not understand it.

My problem:  I am using VB.NET 2003.  As part of my app, I have a
Listview that has a list of directories in the left column.  In the
right column I want to put the total size of each folder.  So, I've
wrote the function to return each size and I can get it to total each
folder line by line.  However, this takes ages!  So, I want to fire off
a thread for each folder and total them all at the same time.  This is
where my problem is.

I can fire off the threads but only if I declare each thread
seperately.  As I do not know how many threads I need, I want to create
a "Thread Array" of some sort.  i.e. Thread(#).Start etc. etc.  This I
do not know how to do.  But, worse still, I wrote a function that
totals up the sizes and returns a value with the total.  This works by
passing the path name as a string to the function.  When I try to do
this via a thread I get an error telling me basically that you cannot
pass arguments to a function in a thread.  So I am stuck!

As a summary, what I want to do is:

- Create x number of threads based on how many rows are in the
listview.
- Fire them all at once (to run together) and pass the path as an
argument.

Is this even possible?  If so, any help would be most appreciated.

Thanks,
Hugh.

Author
22 Jan 2006 11:03 PM
Armin Zingler
"Hugh Janus" <my-junk-acco***@hotmail.com> schrieb
> My problem:  I am using VB.NET 2003.  As part of my app, I have a
> Listview that has a list of directories in the left column.  In the
> right column I want to put the total size of each folder.  So, I've
> wrote the function to return each size and I can get it to total
> each folder line by line.  However, this takes ages!  So, I want to
> fire off a thread for each folder and total them all at the same
> time.  This is where my problem is.

I don't have a solution, but I think it doesn't make sense to use one thread
per directory. This would slow everything down a lot because the HD's
read/write head would have to jump even more if you switch between
directories all the time due to multithreading.

If you wanted to create an array of threads, you would declare it like any
other type of array:

    dim t() as thread
or
    dim t as thread()

Or use an arraylist.


"Parameters and Return Values for Multithreaded Procedures":
http://msdn.microsoft.com/library/en-us/vbcn7/html/vaconParametersReturnValuesForFreeThreadedProcedures.asp


Armin
Author
23 Jan 2006 7:14 AM
Hugh Janus
Yes, I understand about the issue with the drive heads although this is
not so much of a problem for me because the data is stored on a striped
array which will help performance.

I read that a threadpool might help me.  Is this the case?
Author
23 Jan 2006 8:38 AM
Cor Ligthert [MVP]
Hugh,

Let me as another try to tell you because Armin told it right while the disk
was just one example.

Mutltithreading cost forever more processing time.

Only if the processes of the threads are independend from each other than
you can get a faster troughput time. By instance downloading more files from
interenet where there are more senders from which the connection is slower
than the  connection of the receiver.

However, than still is the used processing time more.

(Don't forget however that most used time by a computer is idle time).

I hope that this gives an idea.

Cor
Author
23 Jan 2006 9:24 AM
oxley.daniel
Cor,

I understood what Armin said.  His point was that using multiple
threads would cause excessive CPU cycles because of disk activity.  I
said that this would not be such a problem because I am using a raid-10
stripe set on a high powered SCSI system.  Considering there would
never be more than 10 threads (at a maximum) I don't see that this
would be a great problem for me.  Bearing in mind that doing a large
folder on it's own takes no more than about 45 seconds anyway.

Using some sort of threadpool or multiple threaded code would save me
time during execution.  So I am hoping someone can help me out with the
code/understanding of this and if in the end it does work out a problem
because of the CPU it would be a lesson that I have learnt anyway and
would be a good record in the archive for future people with a similar
question.

Hugh
Author
23 Jan 2006 10:17 AM
Hugh Janus
Sorry, I used a colleagues PC to post this instead of mine, that is why
my reply has the wrong name!
Sorry D, but now you are gonna get spam because your email address is
now public.  oops.
Author
24 Jan 2006 1:22 AM
Dennis
On a single processor computer, all threads use the same processor.  If your
application has to wait for the threads to finish, you would be better off
without threads.  In Windows form applications requiring a user interaction,
I havent' found much use for threads except for something like printing or
writing to a large file to a disk.  There are probably some other speciality
uses of threads but I suspect fopr the most part, threads are very over used
by a lot of non-pros.

--
Dennis in Houston


Show quoteHide quote
"Hugh Janus" wrote:

> Sorry, I used a colleagues PC to post this instead of mine, that is why
> my reply has the wrong name!
> Sorry D, but now you are gonna get spam because your email address is
> now public.  oops.
>
>