How to call void every 0.02 seconds?
Options
Comments
-
Hi, @RandomMan
there is only two options for you.
1. organize while loop in your code, so, that it will call some method every .02 seconds
2. try to use IFiber.ScheduleOnInterval but this will be very unprecise.
I would say that value 0.02 is to high for server side code. value between 50-100 ms should be ok for you
best,
ilya0 -
0.02 = 20 ms
1 second = 1000 ms.
But thanks, I saw Fiber already in one Photon project.
It was used like this:
IFiber updateFiber;
SomeFunc()
{
updateFiber = new PoolFiber();
updateFiber.ScheduleOnInterval(Update, 50, 50);
updateFiber.Start();
{.
But can you say me, what differences between using Fiber like a Timer and standard C# timer?0 -
hi, @RandomMan
inside Fiber still uses Timer, but it enqueues callback to its(fiber) task queue, so you do not have concurrency issues
best,
ilya0 -
Thats how my loop looks like. Pretty standard
private readonly TimeSpan m_TickTimeout = new TimeSpan(0, 0, 0, 0, 20); private readonly Thread m_AIThread; private bool m_Running; private AILooper() { m_Running = true; m_AIThread = new Thread(Loop); } public void Start() { m_AIThread.Start(); } /// <summary> /// Loop. /// </summary> private void Loop() { while (m_Running) { // Call you updates here. } Thread.Sleep(m_TickTimeout); } }
0