public void Post_TryExecute()
        {
            using var context = new TerrariaSynchronizationContext();
            object?state = null;

            context.Post(s => state = s, "test");

            context.TryExecute();

            Assert.Equal("test", state);
        }
Beispiel #2
0
            // Sets up a synchronization context which ensures that continuations run on the main Terraria thread.
            static TerrariaSynchronizationContext SetUpSynchronizationContext()
            {
                var context = new TerrariaSynchronizationContext();

                SynchronizationContext.SetSynchronizationContext(context);

                // We use `Terraria.Main.OnTickForThirdPartySoftwareOnly` to try executing continuations each game tick.
                // We could instead register a `ServerTickEvent` handler, but that would mean that continuations can
                // only run if there are players present on the server.
                Terraria.Main.OnTickForThirdPartySoftwareOnly += () => context.TryExecute();

                return(context);
            }
        public void TryExecute_NoTasks()
        {
            using var context = new TerrariaSynchronizationContext();

            context.TryExecute();
        }