© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•8mo ago•
3 replies
GamerWoona

✅ Custom TimeProvider for WebApi

I am doing a lil api market simulation. Now, I'd like to run a custom time (sped up), for one, run events like budget reports on a quarter-year basis based on it.
From my initial research into the topic, running a custom TimeProvider seems fairly straightforward, though I don't think I can plug that one into EF to have the DateUpdated times in the DB match the in-app time.

What I am unsure about is how to go about the event chain. I was thinking of the TimeProvider running internal Timers based on the simulation speed (that need to be updated and maintained if it is changed) and sending out events based on these but maybe there is a better way.
Also, persisting the in-simulation time over sessions is something I am a bit unsure about. Would have loved to persist that on shutdown but that is probably unreliable but writing it into the db on every GetUtcNow call is a bit much, too?

Checking out the Clock Class, it didn't quite match what I was looking for, so I thought TimeProvider with a few extras could be good enough.

Maybe there is a pre-built solution for this but I am just too blind to see it.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Cookies help Dotnet webapi
C#CC# / help
2y ago
SemanticKernel WebAPI proper DI
C#CC# / help
2y ago
❔ Recommended Session Approach for WebApplication (React frontend, WebApi backend)
C#CC# / help
4y ago