views:

76

answers:

2

I would like my software that scans disk structure to work in background but lowing the priority for the thread that that scans disk structure doesn't work. I mean you still have the feeling of the computer hard working and even freezing even if your program consumes only 1 percent of the processor time. Is it possible to implement "hard disk time consumption" equivalent of CPU consumption in Win32

A: 

Disk accesses are typically measured by a few different metrics transfers per second (which can be broken down into reads/writes), and data read or written per second. If you want to limit the impact of your disk scanning application, one way to do this would be to track one (or both) of these metrics, determine a reasonable cap, and periodically sleep your thread for some time period. Nothing you can do to CPU scheduling is going to be effective at accomplishing this task except in the most diaphanous, indirect way.

peterb
+4  A: 

Since Vista you can lower your IO priority, which is separate from CPU priority. http://msdn.microsoft.com/en-us/library/ms686219(VS.85).aspx

SetPriorityClass(GetCurrentProcess(), PROCESS_MODE_BACKGROUND_BEGIN)

For XP, 2003 and older, you'd have to find some other way to throttle your disk activity, like using Sleep() often.

David