Consider this example:
When the user clicks a button, ClassA fires OnUserInteraction event rapidly 10 times. ClassB is attached to this event and in it’s event handler it fires ClassC‘s Render method. In the Render method the AxisAngleRotation3D is executed, but every single animation is lasting 1 second.
In this scenario all 10 AxisAngleRotation3D animations are executed almost at the same time, but I would want them to execute one after another. As I understand threads, I would probably have to implement a thread queue in ClassB, where the Completed event of the AxisAngleRotation3D signals that the next event is allowed to fire…?
Is this correct and how can I achieve this?
Have a task queue. Simply put, have a
ConcurrentQueue<Func<bool>>field or similar, and add tasks to it as necessary. Then have your task execution thread popFunc<bool>delegates off the queue and invoke them. If they return true, they’re done. If they return false, add them back onto the queue, as they couldn’t complete at that time.Here’s an example: