Threading Question

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

Guest

Dear:

I need to know what should I do for the following scenario:

1. Application will continously listen to a folder waiting a files to be
copied
2. so for each file copies should be a thread to process the file then
deliver the reuslts
3. the expected number of file that maybe copied at same time is more than
20,000 files.
so is using ThreadPool in this case is right solution???
if not what should I use to manage the threads?>
 
Raed Sawalha said:
I need to know what should I do for the following scenario:

1. Application will continously listen to a folder waiting a files to be
copied
2. so for each file copies should be a thread to process the file then
deliver the reuslts
3. the expected number of file that maybe copied at same time is more than
20,000 files.
so is using ThreadPool in this case is right solution???
if not what should I use to manage the threads?>

Personally I'd suggest avoiding the system threadpool, as it's easy to
accidentally deadlock it. You can easily create a custom threadpool
though - I have one you can use in my MiscUtil library.

See http://www.pobox.com/~skeet/csharp/miscutil
 
I downloading Threading DLL, so can I use it without care about thread
managing inside my program.
 
Raed Sawalha said:
I downloading Threading DLL, so can I use it without care about thread
managing inside my program.

What do you mean by "threading DLL"?

You pretty much *always* need to care about thread management in your
program.
 
Oh! I just meant MiscUtil.dll, but realy I ougth to use in Managed C++ so I
did like
this
#using "C:\Utilities\MiscUtil.dll"
using namespace MiscUtil::Threading;

but when application loaded it throws exception that file MiscUtil.dll not
found, do u know the write way to import the DLL , because I used to import
..NET DLLs like this
#using <mscorlib.dll>
using namespace System;
#using "System.dll"
#using "System.Data.dll"
.....etc

but with MiscUtil.dll does not work ,why?
 
Raed Sawalha said:
Oh! I just meant MiscUtil.dll, but realy I ougth to use in Managed C++ so I
did like
this
#using "C:\Utilities\MiscUtil.dll"
using namespace MiscUtil::Threading;

but when application loaded it throws exception that file MiscUtil.dll not
found, do u know the write way to import the DLL , because I used to import
.NET DLLs like this
#using <mscorlib.dll>
using namespace System;
#using "System.dll"
#using "System.Data.dll"
....etc

but with MiscUtil.dll does not work ,why?

I don't know how you do it in Managed C++, I'm afraid - in C# you just
add a reference to the DLL in the project.
 
moving 20,000 files at a time from one location to another. Adding threads
won't help very much (it will help a little, but not much). The reason is
that you are not thread-bound or even processor-bound... you are disk-bound.
In other words, you can't go any faster than the time it takes to move
blocks of data off of your disk (and either back onto the disk or out your
network port).

After more than a small number of threads (<12), there will be no advantage
to adding more threads... so plan to queue the requests and run through the
queue on each thread as fast as you can.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
 
Nick,

However it can give a nice sound hearing that diskhead going from left to
right all the time?

:-))

Cor
 
I agree Nick. I would only add that adding threads would probably not even
help a little and would only slow it down. Would need to test
implementation to be sure.
 
Back
Top