So, I have created an automation script performs a task every minute, on the minute (I want the task to be ran at the :00 second of each minute). As a test, the function that I am calling every minute just writes to console and to a text file that it has ran and at which time it has ran.
I don't know anything about resource usage of apps and how to reduce it, but for some reason this application is using around 17% of my CPU on an i7 8750h cpu.
The entire code for the script is as follows:
Logger.WriteLine("Program starting... @ " + DateTime.Now.ToString("HH:mm:ss"));
static void TestTask()
{
string currentTime = DateTime.Now.ToString("HH:mm:ss");
Logger.WriteLine("Test task ran at: " + currentTime);
}
// This currently runs forever, as there is no boolean condition evaluated to false to break the while loop (which is expected behavior)
while (true)
{
// Evyer minute on the minute
if (DateTime.Now.Second == 0)
{
TestTask();
Thread.Sleep(1000);
}
}
The Logger.WriteLine class is a custom class I created that essentially acts the same as Console.WriteLine as it prints the string to the console, but it also adds it to a stringbuilder that then gets written using stringwriter to a .txt file on my desktop. Could this be the issue?
I also tried creating the exact same program in Python, and it uses the same amount of CPU usage. Both .exe versions of the program use about 5mb of memory which is fine for me, but its just the CPU usage that I would like to reduce.
Anyone know anything I could do? Thanks!