This could be caused by a number of things, but different from each other in how it is caused.
Physical causes:
1) A defective RAM module:
You can download a free memory tester here:
https://www.techpowerup.com/download/techpowerup-memtest64/It will put all of the RAM through various tests, hopefully highlighting if there is a ram problem.
2) A badly seated RAM module:
When you are loading several programs at the same time you are using more memory, this could trigger the problem - with the power off and mains lead removed, and antistatic precautions taken (touch a tap or radiator pipe first to earth yourself out) you could take out and replace the ram modules, or swap them around if you have more than one, this can fix a dodgy or dry connection, or show if one module is defective and the other is not.
3) A dodgy monitor cable:
A bad cable can cause display glitches; check the connections or try a different cable.
4) A badly seated graphics card:
Do you have a separate graphics card, or are you using processor graphics?
If you have a separate graphics card it may be badly seated as in the memory modules above. Remove and replace the card to make sure it is seated properly.
==============================
5) Overheating causes:
Overheating can be caused by blocked vents, dust build-up inside the case and on fans, location of PC too warm etc.
I know you said the computer can be on for some time and not crash, but you could check for temperature problems; graphics overheating can cause display glitches. You can download HWMonitor for free from here:
https://www.cpuid.com/softwares/hwmonitor.htmlRead this page for guidance on temperatures:
https://www.gamingscan.com/optimal-cpu-and-gpu-temperatures-for-gaming/==============================
6) Graphics driver issues:
Make sure your drivers are up to date; if you wish you could uninstall and reinstall the graphics drivers in case they have become corrupted.
==============================
Try some of these out to start narrowing the problem down.