From 9b554f69b0c2406a218156a02a847ee876c3acf7 Mon Sep 17 00:00:00 2001
From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com>
Date: Sat, 7 Aug 2021 14:33:35 -0700
Subject: [PATCH] feat(timers): Adds timer pooling, fixes timer related bugs,
and changes timer api (#667)
### Changes/Fixes:
* Adds timer pooling.
* Allows pool to be configurable in ModernUO.json
* Pool replenishes itself asynchronously if depleted.
* Fixes an issue with barkeeps and town criers
* Fixes an issue with incognito buff icons not being removed
* Fixes an issue with polymorph name mod not being removed
* Fixes several places where timers go on forever even after an object is deleted, keeping a reference (memory leak)
* Eliminates the timer for MiningCart altogether.
* Deletes `AcidSlime` since it is a duplicate of `PoolOfAcid`
* Fixes HonorableExecution and standardizes the code for other Bushido moves.
## Changes to the Timer API:
```cs
public class Timer
{
// Creates a timer that will be returned to the pool once execution stops.
public static void StartTimer(Action callback);
public static void StartTimer(TimeSpan delay, Action callback);
public static void StartTimer(TimeSpan delay, TimeSpan interval, Action callback);
public static void StartTimer(TimeSpan interval, int count, Action callback);
public static void StartTimer(TimeSpan delay, TimeSpan interval, int count, Action callback);
// Creates a timer and returns a token for more control. Requires manual cancellation in order for the timer to be returned to the pool.
// If the token is dereferenced, the timer will be dereferenced too. While not returning a timer to the pool is not considered hazardous, it does defeat the purpose of pooled timers.
public static void StartTimer(Action callback, out TimerExecutionToken token);
public static void StartTimer(TimeSpan delay, Action callback, out TimerExecutionToken token);
public static void StartTimer(TimeSpan delay, TimeSpan interval, Action callback, out TimerExecutionToken token);
public static void StartTimer(TimeSpan interval, int count, Action callback, out TimerExecutionToken token);
public static void StartTimer(TimeSpan delay, TimeSpan interval, int count, Action callback, out TimerExecutionToken token);
// If you aren't sure how to use the API above, or you don't care about performance, then you can use the old RunUO Timer.DelayCall
public static DelayCallTimer DelayCall(Action callback);
public static DelayCallTimer DelayCall(TimeSpan delay, Action callback);
public static DelayCallTimer DelayCall(TimeSpan delay, TimeSpan interval, Action callback);
public static DelayCallTimer DelayCall(TimeSpan interval, int count, Action callback);
public static DelayCallTimer DelayCall(TimeSpan delay, TimeSpan interval, int count, Action callback);
}
public struct TimerExecutionToken
{
public bool Running { get; }
public int Index { get; }
public int RemainingCount { get; }
public DateTime Next { get; }
}
```
## When to use `TimerExecutionToken`?
Use tokens when you want to gain the performance benefit of using a pooled timer, but you need one of the following:
* Access to the next time the timer will tick:`token.Next`
* Access to which interval, how many intervals there are, or how many are remaining: `token.Index`, `token.Count`, and `token.RemainingCount`
* Stop a timer manually.
* Determine if the timer is running: `timer.Running`
* See notes below about requirements for using tokens!
## Notes about using the TimerExecutionToken:
When you opt-in to receive a token, you must call `Cancel()` to return the timer. This can be done inside of the callback, or outside of the callback at any time.
If this is not called and your timer is an infinite interval, then you will create a potential memory leak, or null pointer exception in your callback.
If the timer ends and is stopped, but cancel is not called, then the timer will never return to the pool and stay referenced until the token is deleted or cancel is called. (Memory leak)
## Is this thread safe?
No. The ModernUO timer system is not thread safe at all. If you require a thread safe timer system, contact me and I'll help adapt this system. Keep in mind that there is a massive performance hit to make this thread safe when there are literally no use cases for it.
If you need to synchronize execution, meaning you want to execute code from another thread on the core thread. Let's say you have a discord bot that is pushing commands to the game server. Then use `EventLoopContext.Post(SendOrPostCallback callback, object state);`.
---
.github/workflows/build-test.yml | 2 +-
Projects/Benchmarks/Benchmarks.csproj | 2 +-
.../Server.Tests/Fixtures/ServerFixture.cs | 2 +
.../Server.Tests/Tests/Timer/TimerTests.cs | 6 +-
Projects/Server/EventLoopTasks.cs | 2 +
Projects/Server/IEntity.cs | 2 +-
Projects/Server/Items/Item.cs | 2 +-
Projects/Server/Main.cs | 10 +-
Projects/Server/Mobiles/Mobile.cs | 291 +++++----------
Projects/Server/Network/NetState/NetState.cs | 2 +-
Projects/Server/SecureTrade.cs | 4 +-
Projects/Server/Timer/Timer.DelayCall.cs | 334 ++++++++----------
Projects/Server/Timer/Timer.Pause.cs | 53 ---
Projects/Server/Timer/Timer.Pool.cs | 128 +++++++
Projects/Server/Timer/Timer.TimerWheel.cs | 29 +-
Projects/Server/Timer/Timer.cs | 24 +-
Projects/Server/Timer/TimerExecutionToken.cs | 60 ++++
Projects/Server/World/World.cs | 2 +-
Projects/UOContent/Accounting/Account.cs | 2 +-
.../UOContent/Engines/Bulk Orders/BaseBOD.cs | 2 +-
.../Engines/CannedEvil/ChampionSpawn.cs | 44 +--
.../Engines/ConPVP/AcceptDuelGump.cs | 2 +-
Projects/UOContent/Engines/ConPVP/Arena.cs | 4 +-
.../UOContent/Engines/ConPVP/DuelContext.cs | 80 ++---
.../Engines/ConPVP/Games/BombingRun.cs | 34 +-
.../UOContent/Engines/ConPVP/Games/CTF.cs | 28 +-
.../Engines/ConPVP/Games/DoubleDom.cs | 69 +---
.../Engines/ConPVP/Games/KingOfTheHill.cs | 30 +-
.../Engines/ConPVP/Gumps/AcceptTeamGump.cs | 2 +-
.../UOContent/Engines/ConPVP/Tournament.cs | 25 +-
.../Engines/ConPVP/TournamentRegistrar.cs | 6 +-
.../UOContent/Engines/Craft/Core/Repair.cs | 2 +-
.../UOContent/Engines/Doom/GauntletSpawner.cs | 7 +-
.../Doom/LeverPuzzle/LeverPuzzleController.cs | 15 +-
.../Doom/LeverPuzzle/LeverPuzzleItems.cs | 2 +-
.../UOContent/Engines/Ethics/Core/Ethic.cs | 2 +-
.../Engines/Factions/Core/Election.cs | 8 +-
.../Engines/Factions/Core/Faction.cs | 10 +-
.../Engines/Factions/Core/FactionState.cs | 2 +-
.../Engines/Factions/Core/Keywords.cs | 2 +-
.../UOContent/Engines/Factions/Core/Town.cs | 12 +-
.../Power Faction Items/ClarityPotion.cs | 2 +-
.../Power Faction Items/PowerFactionItem.cs | 4 +-
.../Items/Power Faction Items/StormsEye.cs | 6 +-
.../Factions/Items/Traps/BaseFactionTrap.cs | 26 +-
.../Mobiles/Guards/BaseFactionGuard.cs | 2 +-
Projects/UOContent/Engines/Harvest/Fishing.cs | 2 +-
.../UOContent/Engines/Khaldun/RaisableItem.cs | 3 +-
.../UOContent/Engines/Khaldun/RaiseSwitch.cs | 2 +-
.../Engines/ML Quests/Gumps/RaceChangeGump.cs | 6 +-
.../Engines/ML Quests/MLQuestEntry.cs | 12 +-
.../Engines/ML Quests/Mobiles/SirHelper.cs | 2 +-
.../ML Quests/Objectives/EscortObjective.cs | 10 +-
.../Quests/Core/Items/HornOfRetreat.cs | 10 +-
.../Engines/Quests/Core/QuestSystem.cs | 57 +--
.../Quests/Dark Tides/Items/MaabusCoffin.cs | 4 +-
.../Dark Tides/Mobiles/SummonedPaladin.cs | 4 +-
.../Items/HaochisTreasureChest.cs | 4 +-
.../Study of the Solen Hive/Objectives.cs | 35 +-
.../The Summoning/Items/BellOfTheDead.cs | 2 +-
.../Quests/The Summoning/Mobiles/Chyloth.cs | 6 +-
.../Witch Apprentice/Mobiles/Blackheart.cs | 2 +-
.../Quests/Witch Apprentice/Objectives.cs | 4 +-
.../Character Statue Maker/CharacterStatue.cs | 2 +-
.../CharacterStatuePlinth.cs | 2 +-
Projects/UOContent/Engines/Virtues/Honor.cs | 4 +-
Projects/UOContent/Engines/Virtues/Justice.cs | 2 +-
.../UOContent/Engines/Virtues/Sacrifice.cs | 2 +-
Projects/UOContent/Gumps/ReportMurderer.cs | 2 +-
.../Halloween/2006/Engines/TrickOrTreat.cs | 14 +-
.../Halloween/2009/Engines/PumpkinPatch.cs | 11 +-
.../Halloween/2011/Mobiles/PumpkinHead.cs | 16 +-
.../Halloween/2012/Engines/PlayerZombies.cs | 103 +++---
.../Items/Addons/FlourMillEastAddon.cs | 12 +-
.../Items/Addons/FlourMillSouthAddon.cs | 12 +-
.../UOContent/Items/Addons/JackOLantern.cs | 2 +-
.../Items/Addons/RejuvinationAnkhs.cs | 2 +-
Projects/UOContent/Items/Aquarium/Aquarium.cs | 23 +-
Projects/UOContent/Items/Aquarium/BaseFish.cs | 14 +-
.../Items/Containers/FillableContainers.cs | 33 +-
.../UOContent/Items/Containers/Strongbox.cs | 2 +-
.../StealableArtifactsSpawner.cs | 13 +-
.../UOContent/Items/Farming/FarmableCrop.cs | 2 +-
Projects/UOContent/Items/Guilds/Guildstone.cs | 2 +-
Projects/UOContent/Items/Maps/TreasureMap.cs | 2 +-
Projects/UOContent/Items/Misc/AcidSlime.cs | 106 ------
Projects/UOContent/Items/Misc/Bola.cs | 4 +-
.../UOContent/Items/Misc/DeceitBrazier.cs | 25 +-
.../UOContent/Items/Misc/EffectController.cs | 8 +-
Projects/UOContent/Items/Misc/Firebomb.cs | 52 +--
Projects/UOContent/Items/Misc/Guillotine.cs | 6 +-
Projects/UOContent/Items/Misc/MorphItem.cs | 2 +-
Projects/UOContent/Items/Misc/PoolOfAcid.cs | 9 +-
Projects/UOContent/Items/Misc/Teleporter.cs | 47 +--
Projects/UOContent/Items/Misc/WarningItem.cs | 2 +-
.../Items/Skill Items/Camping/Bedroll.cs | 6 +-
.../Items/Skill Items/Camping/Campfire.cs | 6 +-
.../Carpenter Items/TaxidermyKit.cs | 2 +-
.../Fishing/Misc/SpecialFishingNet.cs | 2 +-
.../Skill Items/Magical/Misc/PotionKeg.cs | 2 +-
.../BaseConflagrationPotion.cs | 18 +-
.../BaseConfusionBlastPotion.cs | 18 +-
.../Explosion Potions/BaseExplosionPotion.cs | 33 +-
.../Potions/Heal Potions/BaseHealPotion.cs | 2 +-
.../Magical/Potions/InvisibilityPotion.cs | 9 +-
.../Items/Skill Items/Misc/FireHorn.cs | 14 +-
.../Musical Instruments/BaseInstrument.cs | 21 +-
.../Skill Items/Ninjitsu/NinjaWeapons.cs | 9 +-
.../Dawn's Music Box/DawnsMusicBox.cs | 12 +-
.../8th Anniversary Items/FountainOfLife.cs | 12 +-
.../CreepyPortrait.cs | 4 +-
.../DisturbingPortrait.cs | 18 +-
.../SacrificialAltar.cs | 22 +-
.../UnsettlingPortrait.cs | 20 +-
.../Special/Heritage Items/FruitTrees.cs | 4 +-
.../Special/Heritage Items/Guillotine.cs | 30 +-
.../Special/Heritage Items/IronMaiden.cs | 13 +-
.../Special/Holiday/Christmas/HolidayTree.cs | 2 +-
.../Items/Special/Holiday/IcyPatch.cs | 34 +-
.../UOContent/Items/Special/Holiday/Wreath.cs | 2 +-
.../Special/House Raffle/HouseRaffleStone.cs | 2 +-
.../Items/Special/ML/GrizzledMareStatuette.cs | 2 +-
.../Special/Mutation Core/PlagueBeastBlood.cs | 113 +++---
.../Mutation Core/PlagueBeastMutationCore.cs | 14 +-
.../Mutation Core/PlagueBeastOrgans.cs | 52 +--
.../Special/Mutation Core/PlagueBeastVein.cs | 29 +-
.../Special Scrolls/ScrollofAlacrity.cs | 2 +-
.../Special/Veteran Rewards/MiningCart.cs | 282 ++++++++-------
.../Special/Veteran Rewards/TreeStump.cs | 21 +-
.../UOContent/Items/Talismans/BaseTalisman.cs | 19 +-
.../Items/Talismans/TalismanSummons.cs | 4 +-
.../UOContent/Items/Traps/FlameSpurtTrap.cs | 11 +-
.../UOContent/Items/Traps/MushroomTrap.cs | 2 +-
Projects/UOContent/Items/Traps/SpikeTrap.cs | 4 +-
.../UOContent/Items/Traps/StoneFaceTrap.cs | 4 +-
Projects/UOContent/Items/Wands/BaseWand.cs | 9 +-
.../Items/Weapons/Abilities/DefenseMastery.cs | 6 +-
.../Weapons/Abilities/FrenziedWhirlwind.cs | 2 +-
.../Items/Weapons/Abilities/MortalStrike.cs | 26 +-
.../Items/Weapons/Abilities/ParalyzingBlow.cs | 16 +-
.../Items/Weapons/Maces/FireworksWand.cs | 2 +-
.../Items/Weapons/Ranged/BaseRanged.cs | 15 +-
Projects/UOContent/Misc/AOS.cs | 24 +-
Projects/UOContent/Misc/AutoRestart.cs | 4 +-
Projects/UOContent/Misc/AutoSave.cs | 2 +-
Projects/UOContent/Misc/BuffIcons.cs | 8 +-
Projects/UOContent/Misc/CharacterCreation.cs | 6 +-
Projects/UOContent/Misc/Cleanup.cs | 2 +-
Projects/UOContent/Misc/ClientVerification.cs | 4 +-
.../Misc/Gifts/Winter2004/Mistletoe.cs | 2 +-
Projects/UOContent/Misc/Guild.cs | 2 +-
Projects/UOContent/Misc/ShardPoller.cs | 11 +-
Projects/UOContent/Misc/Weather.cs | 2 +-
Projects/UOContent/Mobiles/AI/BaseAI.cs | 2 +-
.../UOContent/Mobiles/Animals/Mounts/Hiryu.cs | 2 +-
.../Mobiles/Animals/Mounts/LesserHiryu.cs | 2 +-
Projects/UOContent/Mobiles/BaseCreature.cs | 33 +-
.../UOContent/Mobiles/Familiars/ShadowWisp.cs | 2 +-
.../Mobiles/Monsters/AOS/DemonKnight.cs | 2 +-
.../Mobiles/Monsters/AOS/ShadowKnight.cs | 13 +-
.../Monsters/Humanoid/Magic/Betrayer.cs | 2 +-
.../Monsters/Humanoid/Magic/SavageShaman.cs | 2 +-
.../Monsters/Humanoid/Melee/Juggernaut.cs | 2 +-
.../Mobiles/Monsters/LBR/Jukas/JukaMage.cs | 11 +-
.../Mobiles/Monsters/LBR/Meers/MeerEternal.cs | 6 +-
.../Mobiles/Monsters/LBR/Meers/MeerMage.cs | 77 ++--
.../Mobiles/Monsters/ML/Animal/Ferret.cs | 4 +-
.../Mobiles/Monsters/ML/Special/Ilhenir.cs | 30 +-
.../Mobiles/Monsters/ML/Special/Meraktus.cs | 2 +-
.../Monsters/Mammal/Melee/VorpalBunny.cs | 6 +-
.../Mobiles/Monsters/Misc/Melee/Golem.cs | 2 +-
.../Monsters/Misc/Melee/PlagueBeastLord.cs | 16 +-
.../Mobiles/Monsters/SE/BakeKitsune.cs | 13 +-
.../UOContent/Mobiles/Monsters/SE/Kappa.cs | 5 +-
Projects/UOContent/Mobiles/PlayerMobile.cs | 41 ++-
.../Mobiles/Townfolk/BaseEscortable.cs | 2 +-
.../UOContent/Mobiles/Townfolk/TownCrier.cs | 52 ++-
.../UOContent/Mobiles/Vendors/BaseVendor.cs | 2 +-
.../UOContent/Mobiles/Vendors/GenericBuy.cs | 17 +-
.../Mobiles/Vendors/PlayerBarkeeper.cs | 21 +-
.../UOContent/Mobiles/Vendors/PlayerVendor.cs | 8 +-
.../Mobiles/Vendors/VendorInventory.cs | 2 +-
Projects/UOContent/Multis/Boats/BaseBoat.cs | 80 ++---
Projects/UOContent/Multis/Camps/BaseCamp.cs | 9 +-
Projects/UOContent/Multis/Houses/BaseHouse.cs | 16 +-
.../UOContent/Multis/Houses/MovingCrate.cs | 4 +-
.../UOContent/Multis/Houses/PreviewHouse.cs | 2 +-
Projects/UOContent/Skills/AnimalTaming.cs | 2 +-
Projects/UOContent/Skills/Discordance.cs | 10 +-
.../Special Systems/Engines/GiftGiving.cs | 2 +-
.../UOContent/Spells/Bushido/Confidence.cs | 104 +++---
.../UOContent/Spells/Bushido/CounterAttack.cs | 39 +-
Projects/UOContent/Spells/Bushido/Evasion.cs | 53 ++-
.../Spells/Bushido/HonorableExecution.cs | 9 +-
.../UOContent/Spells/Bushido/SamuraiSpell.cs | 33 +-
.../UOContent/Spells/Chivalry/DivineFury.cs | 28 +-
.../UOContent/Spells/Chivalry/EnemyOfOne.cs | 19 +-
Projects/UOContent/Spells/Fifth/Incognito.cs | 17 +-
Projects/UOContent/Spells/Fifth/MindBlast.cs | 11 +-
Projects/UOContent/Spells/Fourth/Curse.cs | 2 +-
Projects/UOContent/Spells/Fourth/ManaDrain.cs | 2 +-
.../Spells/Mysticism/EagleStrikeSpell.cs | 2 +-
.../Spells/Necromancy/AnimateDeadSpell.cs | 6 +-
.../UOContent/Spells/Necromancy/EvilOmen.cs | 2 +-
.../UOContent/Spells/Ninjitsu/AnimalForm.cs | 71 ++--
.../UOContent/Spells/Ninjitsu/Backstab.cs | 2 +-
.../Spells/Ninjitsu/SurpriseAttack.cs | 25 +-
.../UOContent/Spells/Seventh/Polymorph.cs | 21 +-
.../UOContent/Spells/Sixth/Invisibility.cs | 27 +-
.../Spells/Spellweaving/AttuneWeapon.cs | 2 +-
.../Spells/Spellweaving/EtherealVoyage.cs | 4 +-
.../Spells/Spellweaving/GiftOfLife.cs | 2 +-
.../Spells/Spellweaving/GiftOfRenewal.cs | 2 +-
.../Spells/Spellweaving/ImmolatingWeapon.cs | 2 +-
.../Spellweaving/Items/TransientItem.cs | 9 +-
.../Spells/Spellweaving/Mobiles/NatureFury.cs | 4 +-
.../Spells/Spellweaving/Thunderstorm.cs | 23 +-
Projects/UOContent/UOContent.csproj | 2 +-
azure-pipelines.yml | 4 +-
219 files changed, 1897 insertions(+), 2241 deletions(-)
delete mode 100644 Projects/Server/Timer/Timer.Pause.cs
create mode 100644 Projects/Server/Timer/Timer.Pool.cs
create mode 100644 Projects/Server/Timer/TimerExecutionToken.cs
delete mode 100644 Projects/UOContent/Items/Misc/AcidSlime.cs
diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml
index 8c677d1c3..2d805ab91 100644
--- a/.github/workflows/build-test.yml
+++ b/.github/workflows/build-test.yml
@@ -26,7 +26,7 @@ jobs:
- name: Setup .NET 5
uses: actions/setup-dotnet@v1
with:
- dotnet-version: 5.0.301
+ dotnet-version: 5.0.302
- name: Build
run: ./publish.cmd
- name: Test
diff --git a/Projects/Benchmarks/Benchmarks.csproj b/Projects/Benchmarks/Benchmarks.csproj
index e0ab71eea..cd7d4a26c 100644
--- a/Projects/Benchmarks/Benchmarks.csproj
+++ b/Projects/Benchmarks/Benchmarks.csproj
@@ -9,7 +9,7 @@
true
-
+
diff --git a/Projects/Server.Tests/Fixtures/ServerFixture.cs b/Projects/Server.Tests/Fixtures/ServerFixture.cs
index f286d1051..fa4669c32 100644
--- a/Projects/Server.Tests/Fixtures/ServerFixture.cs
+++ b/Projects/Server.Tests/Fixtures/ServerFixture.cs
@@ -7,6 +7,8 @@ namespace Server.Tests
// Global setup
static ServerFixture()
{
+ Core.LoopContext = new EventLoopContext();
+
Core.Expansion = Expansion.EJ;
// Load Configurations
diff --git a/Projects/Server.Tests/Tests/Timer/TimerTests.cs b/Projects/Server.Tests/Tests/Timer/TimerTests.cs
index d7a005626..30fdbcd7a 100644
--- a/Projects/Server.Tests/Tests/Timer/TimerTests.cs
+++ b/Projects/Server.Tests/Tests/Timer/TimerTests.cs
@@ -25,8 +25,7 @@ namespace Server.Tests
Timer.Init(timerTicks.Ticks);
- var timer = Timer.DelayCall(TimeSpan.FromMilliseconds(ticks), action);
- timer.Start();
+ Timer.StartTimer(TimeSpan.FromMilliseconds(ticks), action);
var tickCount = expectedTicks / 8;
@@ -53,8 +52,7 @@ namespace Server.Tests
Timer.Init(timerTicks.Ticks);
- var timer = Timer.DelayCall(TimeSpan.FromMilliseconds(delay), TimeSpan.FromMilliseconds(interval), count, action);
- timer.Start();
+ Timer.StartTimer(TimeSpan.FromMilliseconds(delay), TimeSpan.FromMilliseconds(interval), count, action);
var tickCount = (expectedDelayTicks + (expectedIntervalTicks * count - 1)) / 8;
diff --git a/Projects/Server/EventLoopTasks.cs b/Projects/Server/EventLoopTasks.cs
index a96d7aa53..3ead229cb 100644
--- a/Projects/Server/EventLoopTasks.cs
+++ b/Projects/Server/EventLoopTasks.cs
@@ -32,6 +32,8 @@ namespace Server
public override SynchronizationContext CreateCopy() => new EventLoopContext();
+ public void Post(Action d) => _queue.Enqueue(d);
+
public override void Post(SendOrPostCallback d, object state) => _queue.Enqueue(() => d(state));
public override void Send(SendOrPostCallback d, object state)
diff --git a/Projects/Server/IEntity.cs b/Projects/Server/IEntity.cs
index 827eb28ae..4dbb61470 100644
--- a/Projects/Server/IEntity.cs
+++ b/Projects/Server/IEntity.cs
@@ -108,7 +108,7 @@ namespace Server
public void Deserialize(IGenericReader reader)
{
// Should not actually be saved
- Timer.DelayCall(Delete);
+ Timer.StartTimer(Delete);
}
public void Serialize(IGenericWriter writer)
diff --git a/Projects/Server/Items/Item.cs b/Projects/Server/Items/Item.cs
index cffee465a..c54d6ae40 100644
--- a/Projects/Server/Items/Item.cs
+++ b/Projects/Server/Items/Item.cs
@@ -3027,7 +3027,7 @@ namespace Server
if (HeldBy != null)
{
- Timer.DelayCall(FixHolding_Sandbox);
+ Timer.StartTimer(FixHolding_Sandbox);
}
// if (version < 9)
diff --git a/Projects/Server/Main.cs b/Projects/Server/Main.cs
index 6944fc26d..01e46e8eb 100644
--- a/Projects/Server/Main.cs
+++ b/Projects/Server/Main.cs
@@ -47,7 +47,7 @@ namespace Server
private static int _itemCount;
private static int _mobileCount;
- private static EventLoopContext _eventLoopContext;
+ public static EventLoopContext LoopContext { get; set; }
private static readonly Type[] _serialTypeArray = { typeof(Serial) };
@@ -366,9 +366,9 @@ namespace Server
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
- _eventLoopContext = new EventLoopContext();
+ LoopContext = new EventLoopContext();
- SynchronizationContext.SetSynchronizationContext(_eventLoopContext);
+ SynchronizationContext.SetSynchronizationContext(LoopContext);
foreach (var a in args)
{
@@ -505,7 +505,9 @@ namespace Server
events += NetState.Slice();
// Execute captured post-await methods (like Timer.Pause)
- events += _eventLoopContext.ExecuteTasks();
+ events += LoopContext.ExecuteTasks();
+
+ Timer.CheckTimerPool(); // Check for pool depletion so we can async refill it.
_tickCount = 0;
_now = DateTime.MinValue;
diff --git a/Projects/Server/Mobiles/Mobile.cs b/Projects/Server/Mobiles/Mobile.cs
index 0e79e03ba..aee6309fa 100644
--- a/Projects/Server/Mobiles/Mobile.cs
+++ b/Projects/Server/Mobiles/Mobile.cs
@@ -454,7 +454,7 @@ namespace Server
private List