Home > Net >  How do not take up too much CPU resources to consume time?
How do not take up too much CPU resources to consume time?

Time:09-23

Cannot be used directly sleep, can't call the three routine, such as ping, such as

My train of thought is N the loop, but found that takes up more than 50% of the CPU, have any good ideas?

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - line -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
And thought about the use of network IO delay to holding time, there's a better way

CodePudding user response:

Why don't sleep? You mean it is want to sleep, but not sleep? With no body is honesty to say, you this desire, the other hand, says he wants to, the body is to move back.
If you don't want to block the main thread, then perform in a new thread, do not affect the main thread, or using asynchronous method.

CodePudding user response:

//introduction of high performance counter API, complete timing on CPU count
[DllImport (" Kernel32. DLL)]
Private static extern bool QueryPerformanceCounter (out long lpPerformanceCount);

//get the current the working frequency of CPU
[DllImport (" Kernel32. DLL)]
Private static extern bool QueryPerformanceFrequency (out long lpFrequency);
  •  Tags:  
  • C#
  • Related