Edited: Two questions were originally posed, they were checked and received an answer.
I am creating a multi-threaded reader / writer that browses files in a set of folders. He does this every 5 minutes or less if the user indicates it.
My current problem is that the stream will look at files with too much gluttony. I want to limit the thread to using a maximum of 30% of the processor (or the user-specified amount if they want faster or slower). The reason for this is that it is a program that should always be turned on, and I do not want it to stop them from browsing the Internet or using other programs at the same time. I personally note that streaming programs that use 100% of the CPU screw with other programs, even if they are set to a lower priority, and try to avoid this.
I thought about using PerformanceCounter to check CPU usage, I hope that it identifies the program and adds more sleep cycles if performance (in general, and in my program, in particular, it finds) starts to peak. I did not find any documentation on limiting the use of a thread processor, except for "lol, why bother?", "Not really feasible" for no reason (which is completely normal - most people want the thread to be executed as soon as possible, and cannot be a way to make it inherent in .Net or another C # library).
Does anyone know another way to set the priority lower or add extra overhead using the PerformanceCounter / some other CPU monitor? Thank.
source
share