How to call void every 0.02 seconds?

Options
Hello. I wanna call one void every 0.02 seconds on server-side. (like timestep FixedUpdate in Unity) how can I do that?

Comments

  • chvetsov
    Options
    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,
    ilya
  • RandomMan
    RandomMan
    edited July 2017
    Options
    0.02 = 20 ms :smile:
    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?
  • chvetsov
    Options
    hi, @RandomMan

    inside Fiber still uses Timer, but it enqueues callback to its(fiber) task queue, so you do not have concurrency issues

    best,
    ilya
  • jingyiwang
    Options
    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);
                }
            }