469,097 Members | 1,561 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,097 developers. It's quick & easy.

Threading Question

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?>
Nov 16 '05 #1
8 3078
Raed Sawalha <Ra*********@discussions.microsoft.com> wrote:
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

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
I downloading Threading DLL, so can I use it without care about thread
managing inside my program.

"Jon Skeet [C# MVP]" wrote:
Raed Sawalha <Ra*********@discussions.microsoft.com> wrote:
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

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3
Raed Sawalha <Ra*********@discussions.microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
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?

"Jon Skeet [C# MVP]" wrote:
Raed Sawalha <Ra*********@discussions.microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #5
Raed Sawalha <Ra*********@discussions.microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6
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.
--
"Raed Sawalha" <Ra*********@discussions.microsoft.com> wrote in message
news:8D**********************************@microsof t.com...
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?>

Nov 16 '05 #7
Nick,

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

:-))

Cor
Nov 16 '05 #8
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.

--
William Stacey, MVP
http://mvp.support.microsoft.com

"Nick Malik [Microsoft]" <ni*******@hotmail.nospam.com> wrote in message
news:xcWAd.257662$5K2.166205@attbi_s03...
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.
--
"Raed Sawalha" <Ra*********@discussions.microsoft.com> wrote in message
news:8D**********************************@microsof t.com...
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?>



Nov 16 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

65 posts views Thread by Anthony_Barker | last post: by
19 posts views Thread by Jane Austine | last post: by
3 posts views Thread by David Harrison | last post: by
4 posts views Thread by Antal Rutz | last post: by
6 posts views Thread by CK | last post: by
7 posts views Thread by Anthony Nystrom | last post: by
4 posts views Thread by Bob | last post: by
4 posts views Thread by DBC User | last post: by
19 posts views Thread by frankiespark | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.