C
Cider123
I ran into a situation where my Window Service had to process 100,000+
files, when I first noticed I needed to tweak various routines.
Everything runs fine, but here's what I ran into:
In the routine that loops through the file buffer:
for (int i=0;i < _Buffer.length; i++)
{
// Code here
}
If I run it as is, it throttles CPU usage 100%.
If I toss in a simple statement:
Thread.Sleep(1);
The CPU usage throttles around 0-3% as it works through the list.
The difference in files processed is amazingly different though,
something to the tune of 9-10,000 files without the Sleep. 800-1000
files with. (Report dumped once a minute to Event Log).
Looking through various code in this Newsgroup, I've seen
Thread.Sleep(0) instead of Thread.Sleep(1).
2 Questions I have are:
1) Why use 0 instead of 1 if you actually want the Thread to sleep?
2) Is there a better way to run a process that is I/O intensive, SQL
intensive and keep the CPU throttle within reason, other than
incorporating Thread.Sleep statements within the looping mechanisms ?
files, when I first noticed I needed to tweak various routines.
Everything runs fine, but here's what I ran into:
In the routine that loops through the file buffer:
for (int i=0;i < _Buffer.length; i++)
{
// Code here
}
If I run it as is, it throttles CPU usage 100%.
If I toss in a simple statement:
Thread.Sleep(1);
The CPU usage throttles around 0-3% as it works through the list.
The difference in files processed is amazingly different though,
something to the tune of 9-10,000 files without the Sleep. 800-1000
files with. (Report dumped once a minute to Event Log).
Looking through various code in this Newsgroup, I've seen
Thread.Sleep(0) instead of Thread.Sleep(1).
2 Questions I have are:
1) Why use 0 instead of 1 if you actually want the Thread to sleep?
2) Is there a better way to run a process that is I/O intensive, SQL
intensive and keep the CPU throttle within reason, other than
incorporating Thread.Sleep statements within the looping mechanisms ?