CPU usage becomes very high at runtime

I recently created a service that uses a single thread to periodically process information. The service was created using Microsoft Visual Studio 2010 Express. I noticed that the processor load took off on the moon (CPU load at 100%).

Later, out of curiosity, I built a very small program in which everything she does starts a small thread or timer, and then starts an incredibly long cycle. I also switched from creating a console application to a Windows Form application. I was able to reduce my problem by switching the type of program being created.

I tried to lower the priority of the stream:

System.Threading.Thread.CurrentThread.Priority = ThreadPriority.Lowest;

I also tried setting the priority class

Process p = Process.GetCurrentProcess();
p.PriorityClass = ProcessPriorityClass.BelowNormal;

I also thought that CPU usage could be high due to working in a virtual machine. But this theory did not lead me anywhere. This is pretty funny. I don’t know where else to turn. I'm not sure why starting a timer or thread would send my CPU usage through the ceiling just like in the .NET Framework. I have never experienced this when creating COM objects. Does anyone have any bright ideas on where I can go?

Thanks for your time in advance.

+3
source share
2 answers

If you repeat the loop in your thread, this can lead to high CPU utilization. Have you tried to add a pause to the flow between cycles?

Thread.Sleep(1000);
+2
source

, .

Visual Studio, CPU, "Break", . , , , , .

, . , .

+3

Source: https://habr.com/ru/post/1775738/


All Articles