c#


System.Threading.Timer freezing computer


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:
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:
What is causing my computer to lock up to the point of having to hold the power button.
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!
Without knowing the code inside getNewPath(), it is impossible to even guess the reason. And it is hard to believe that is only a simple A* path finding algorithm
Here are some points to start the investigation
What is the CPU usage rate before halt happens? What it is the rate when it happens? Which process has the highest rate?
What is the disk, network, memory usage rate?
Beside the above, does getNewPath consume other resources?
You can print 5 messages. But are they printed before/inside/after getNewPath
Do you have source code for getNewPath? Can you modify code in getNewPath?
Is getNewPath thread safe? Does it create more threads?
There are probably more things to look at. But these should be enough to get you started. And they are necessary for anyone to give meaning suggestions.

Related Links

Converting byte array to image
Elasticsearch NEST DisMax MoreLikeThis query forms empty json string
RemotingException thrown when invoking remote object from NUnit
C# HttpClient ProtocolViolationException [duplicate]
How to use Caliburn Micro Event Aggregator in a ViewModel in WPF
.Net multiple console apps projects in a solution to be a referenced in one console app project
Register Apple Service using a .pem certificate
How to do Dynamic Linq
Generic Calls to stored procedure for data download from C#
_controlfp does not prevent DivideByZeroException
Linq to SQL query to find partial duplicates
ConfigurationManager.AppSettings vs Constants Class
Visual Studio 2015 RC C# Intellisense - some settings missing
Dependency injection best practices [duplicate]
Use mapCruncher tiles with Gmap.Net
How to searching in SQL database using WinForm datetimepicker C#

Categories

HOME
phantomjs
watson-iot
crm
singleton
coordinates
docker-compose
procmon
markdown
browserstack
rename
core-data
hdf5
javascript-debugger
yui
openscad
amazon-data-pipeline
web-parts
wallet
civicrm
restructuredtext
gnu-screen
connection-pooling
windows-mobile
dynamics-ax-2012-r3
jbossfuse
opencsv
availability
jsonapi-resources
offset
fastadapter
apache-falcon
campaign-monitor
respect-validation
console.readline
ng-lightning
aspnetboilerplate
flume-ng
datagridviewcombobox
android-doze-and-standby
spring-webflow-2
spring-data-commons
serverless-architecture
emacs24
runtime-permissions
ajv
xamarin-test-cloud
kendo-scheduler
selection-sort
business-catalyst
iban
vertex-shader
nimbus
weblogic-maven-plugin
php-java-bridge
laterjs
paypal-subscriptions
custom-build-step
alchemy
jersey-test-framework
instabug
askbot
gitk
android-togglebutton
first-order-logic
pdcurses
gcc-warning
parseexception
crtdbg.h
kss
livescript
episerver-7
node-amqp
xtify
mahara
surfaceview
cab
wpd
backbone-views
azure-scheduler
magicsuggest
linear-interpolation
webpage-screenshot
sup
backlight
jqtransform
lwp
noise-reduction
fxcopcmd
conditional-operator
arraycollection
qprocess
numerical-computing
pkcs#7
pixel-bender
onresize
paperless

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App