System.Threading.Timer freezing computer

dangdongho3

New member
Joined
May 30, 2018
Messages
1
Programming Experience
Beginner
I am working on creating a game, and I have a pathfinding function that takes about 100 ms. I have 5 enemies, each with this function in the contstructor:

Code:
newPath = new System.Threading.Timer((e)=>{
getNewPath
();//The function that takes ~100 ms
},null,0,5000);

Now, I am using System.Threading.Timer at an earlier point in the program (to run once every 50 ms just for a step function, to update positions and such). That one works fine, but if I run this function (don't forget I have 5 enemies, so it's running 5 times every 5 seconds), my whole entire computer just freezes. Now I don't have a crappy computer (it's not the best, but it's plenty good for what i'm using it for), so I don't know what the issue is. Even if all timers run one after the other (which they shouldn't do, they should run at the same time), the most it should take is 500ms (or half a second), yet it completely kills my computer, to the point where my mouse doesn't move, I can't Ctrl-Alt-Del, and I have to just hold the power button until it turns off.
I tested putting a simple print function in place of the getNewPath(), and it worked flawlessly and as expected, so I don't really know what the issue is.
My questions are:


  1. What is causing my computer to lock up to the point of having to hold the power button.
  2. Is there something I can use other than System.Threading.Timer that will give me the desired result without completely killing my computer? (Being able to run this function up to ~20 times at once, since it's an MMO and there could potentially be hundreds of enemies that it needs to do pathfinding updates on).

Thanks!
 
Back
Top Bottom