I need to induce a variable amount of lag in vb.net. System should be noticeably slower.
I can raise the CPU usage of the program with infinite loops and some variable creation/assignments, but how can I actually cause lag?
I understand this is an odd request, but I appreciate any help and would appreciate it being taken seriously. This is NOT being used maliciously.
I’d like to have an “InvokeLag” sub which will perform an action to slow down the computer, the faster the function is called the faster it lags. The function should be as mundane as possible, not modifying anything or doing anything to cause damage other than simple lag.
Thanks for your help!
EDIT: Preferably only achieving this effect with crazy math operations and making variables and such. Nothing system if possible.
What about creating a new thread with the highest priority? Calculating Pi will never end and with a high priority it should lag your system down. If you have several processors you could start several threads to calculate pi or have a separate program that calculates pi and start several processes of it?
or
CalculatePi
MSDN
Update:
I think Eric might have a good point about SpinWait and it might be more what you are looking for:
There is no System IO, its basically just a tight loop which does not give up its processing time. I am sure if you used my suggestion of spawning several threads with the highest priority with Eric’s suggestion SpinWait you would achieve what you are looking for. This would also reduce the amount of code you would need to write.