ffmediaelement icon indicating copy to clipboard operation
ffmediaelement copied to clipboard

Loop exit condition in StepTimer.cs

Open igvk opened this issue 3 years ago • 4 comments

Issue Title

There is an endless loop in Primitives/StepTimer.cs Presumably, there should be an exit condition in it.

Issue Categories

  • [x] Bug

Version Information

  • [x] Build From Master branch

Sample Code

This is the code of the ExecuteCallbacks( function that never returns:

        private static void ExecuteCallbacks(object state)
        {
            while (true)
            {
                TickCount++;
                if (TickCount >= 60)
                {
                    Resolution = TimeSpan.FromMilliseconds(Stopwatch.Elapsed.TotalMilliseconds / TickCount);
                    Stopwatch.Restart();
                    TickCount = 0;

                    // Debug.WriteLine($"Timer Resolution is now {Resolution.TotalMilliseconds}");
                }

                Parallel.ForEach(RegisteredTimers, (t) =>
                {
                    if (t.IsRunningCycle || t.IsDisposing)
                        return;

                    t.IsRunningCycle = true;

                    Task.Run(() =>
                    {
                        try
                        {
                            t.UserCallback?.Invoke();
                        }
                        finally
                        {
                            t.IsRunningCycle = false;
                        }
                    });
                });

                while (PendingAddTimers.TryDequeue(out var addTimer))
                    RegisteredTimers.Add(addTimer);

                while (PendingRemoveTimers.TryDequeue(out var remTimer))
                    RegisteredTimers.Remove(remTimer);

                Task.Delay(Constants.DefaultTimingPeriod).Wait();
            }
        }

igvk avatar Oct 21 '21 22:10 igvk

I think it is a static Callback method not a bug.

Mitra-M avatar Nov 11 '21 12:11 Mitra-M

Ok, the problem with this is that there is no way to exit the thread and unload ffme objects when closing video window. This could be ok when this is all that a program does, and closing video means exiting the program.. And what if playing some video file is only one of the functions in software?

igvk avatar Nov 11 '21 14:11 igvk

This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.

stale[bot] avatar Apr 16 '22 19:04 stale[bot]

Ok, the problem with this is that there is no way to exit the thread and unload ffme objects when closing video window. This could be ok when this is all that a program does, and closing video means exiting the program.. And what if playing some video file is only one of the functions in software?

that's a background thread, so if there is no umanaged object in the queue, i think it should be fine.

jcyuan avatar Sep 11 '23 09:09 jcyuan