Re: Threading question



On 3 фев, 04:09, "John Rogers" <johnrogers2...@xxxxxxx> wrote:
I have some code that does a recursive copy of whatever folder I give to
it to copy the structure where I want it.  I have it running in a single
thread
to make it a bit more efficient.  So far it works good, but I am trying to
add
more directories so I can do a bulk copy.

Every article that I have read on threads have always showed two different
functions to run your two threads etc.  My idea is to make a little utility
that
does the same thing as a download manager, but instead it will copy files to
different folders drives etc.

This is where I am lost on the threading issues.

I want to add every dir to a listview, lets say I have some items in a
listview.

c:\backup
c:\source
c:\drivers
c:\utils

I want to copy these items to d:\BACKUPS

Now in the listview (this is my dilemma) I want to start a filecopy of every
checked item in a different thread and copy them to the destination dir.
I know how to go through the listview to see what is checked and what is
not,
but the threading part is whats getting me lost.

Also, do I need a different routine to copy the files for each thread?  I
ask this
because I do not think that I can use the same file copy routine for all of
the threads
running at the same time.

CopyFilesandDirs() etc.

I hope I explained this with enough detail, let me number a few things.

1) Go through the listview and find each checked item.
2) Copy each checked item using a different thread to the destination dir.
3) Only run about 3-4 threads at once, no more than that.

Appreciate any help guys.

John

Hi, John

I think multithreaded implementation in this case won't benefit much,
because bottleneck in this case is hard drive but not CPU, unless you
are copying from/to many physical drives.
I suspect in some cases it can be even slower.

Nonetheless, to implement multithreaded copy I would create a Queue
where I put
all items to be copied. Then I would create 3-4 threads, which will
run the same routine.
This routine will take an item from the Queue in loop and perform
corresponding copy operation.
If there's no items left in the Queue the routine (thread) will
finish. You will need to lock the queue
when you unqueue items from it and probably you will also want to wait
until all threads stop.

Thanks,
Sergey
.



Relevant Pages

  • Hashtable object problem in multithreading
    ... The problem is the time needed to fill the Listview control. ... this Hashtable is a declared as friend variable (Friend Queue as ... worker takes one or some books from the shell and puts them on the floor ...
    (microsoft.public.dotnet.languages.vb)
  • Re: [linux-pm] question on resume()
    ... Rafael is wrong; wake_updoesn't remove a task from a wait queue. ... Thus calling wake_upon a task in the refrigerator will accomplish ... The I/O's completion routine generally _will_ end up calling ...
    (Linux-Kernel)
  • Re: [linux-pm] question on resume()
    ... wake_updoesn't remove a task from a wait queue. ... queue after verifying that the necessary condition has been satisfied. ... Thus calling wake_upon a task in the refrigerator will accomplish ... The I/O's completion routine generally _will_ end up calling ...
    (Linux-Kernel)
  • Re: Why the following code is faster executed when placed in the form?
    ... I like your idea of using temporary local variables. ... You rightly noticed that I am passing lv variable to my routine, ... processes more then one ListView at the time. ... Public Sub ShiftColumns ...
    (microsoft.public.vb.general.discussion)
  • Re: And unique and persistent ID for an ListView entry ?
    ... note that it is technically incorrect to send messages to a window ... All the other threads could update the queue. ... look at the documentation for a listview message that finds items. ... search-and-change action. ...
    (microsoft.public.win32.programmer.ui)

Loading