Home > Enterprise >  Does using the wait function allow your pc to cool down?
Does using the wait function allow your pc to cool down?

Time:04-28

When I am running a macro, after a while my computer gets very hot. I am curious to know if I told the macro to wait for X minutes (using the wait function) when it was halfway through the script, would this help it to cool off as it won't be performing any intensive calculations or processes, and then after it waited and presumably cooled down it could resume and complete the rest of the script?

Thanks in advance for any replies

Note 1: I am aware that my computer getting hot is a symptom of inefficient code, and that I should address whatever underlying issues are in my code to make sure that the computer doesn't struggle to run it. Putting that to one side, I would appreciate responses to the issue of whether waiting is in anyway helpful to cooling my pc down.

Note 2: I am aware of setting manual calculations off, screen updating off, and animations off as a means to getting macros to run more quickly.

CodePudding user response:

If you use a real sleep function, then yes - code execution will be halted and the thread is put in sleep mode. In this example, the Sleep method is derived from kernel32.dll:

Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal Milliseconds As LongPtr)

Sub wait_test()
  Debug.Print "Start"
  
  ' ... Code block 1
  
  ' Wait for 5 seconds
  Sleep 5000

  ' ... Code block 2
  
  Debug.Print "End"
End Sub

Although, if the root cause is your machine overheating, I'd look elsewhere, as a modern CPU should be able to handle 100% load for longer durations. (e.g. the thermal paste under the cooler)

  • Related