I need to do some pretty fast recalculation ~every second.
What is the best way to do that? Is using dedicated thread and Thread.Sleep is ok?
Task.Factory.StartNew(() =>
{
while (true)
{
RecalculateState();
Thread.Sleep(1000);
}
}, TaskCreationOptions.LongRunning);
That would work – but another alternative would be to use a timer, e.g.
System.Threading.TimerorSystem.Timers.Timer.You should think about:
RecalculateStatemethod entirely safe to be called from arbitrary threads?