c# - Why does Thread.Sleep( ... ) avoids CPU using 100% of a heavy execution from a multithread windows service based application? -
i have huge text parsing windows service application takes 20 minutes finish whole process, , consumes 100% cpu. set thread.sleep(500) @ end of each item in loop , cpu consumption between 70% , 0% !!!! , takes 3 hours finish fine business case.
the question might obvious not me, why did delay create consume less cpu?
when looking @ cpu usage in task manager you're actually looking @ percentage of non-noop commands on given interval of time. given core of cpu can't 34% on. either it's doing something, or it's not, can switch , forth literally billions of times per second. inserting sleep
commands result cpu spending lot more time doing nothing, though has work doing. when time spent nil averaged time spent doing result less 100% usage. if slept longer periods of time, did less often, you'd see jumping between 0 , 100% (which what's happening, can't visualize currently).
c# .net multithreading
No comments:
Post a Comment