I'm working on rearchitecting a game engine in which multiple concurrent scripts run in parallel threads, which unfortunately occasionally gives rise to race conditions.  I'm trying to set it up so that all the game logic will run in the same thread, and any blocking call will run as async.Rendering needs to absolutely have the highest priority, to maintain the frame rate.  After rendering, there will be so many milliseconds left in a frame.  So what I need is some sort of Task scheduler that will run scripts in this time while preserving the invariant.  From a bit of research, it appears that a custom SynchronizationContext might be part of the solution, but I don't know enough about the nitty-gritty details of async to work it all out.What I need it to be able to do:Keep track of all scheduled Tasks that are not currently blocked on an await and are ready to run.When the Run(int time) method is called, it has time milliseconds to run as many of these Tasks with outstanding work as possible.Return once the time is up, or when there are no more non-blocked Tasks to work on, whichever comes first.Does anyone know how I would go about writing such a thing?
Creating a (System.Threading.Tasks.)Task scheduler
c#;async;scheduling