Re: Threading question
- From: Sergey Zyuzin <forever.zet@xxxxxxxxx>
- Date: Sun, 3 Feb 2008 01:25:25 -0800 (PST)
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
.
- Follow-Ups:
- Re: Threading question
- From: John Rogers
- Re: Threading question
- References:
- Threading question
- From: John Rogers
- Threading question
- Prev by Date: C# - Delay at Begining
- Next by Date: Re: C# - Delay at Begining
- Previous by thread: Re: Threading question
- Next by thread: Re: Threading question
- Index(es):
Relevant Pages
|
Loading