C#
C#

help

Root Question Message

thinker227
thinker22710/3/2022
Schedule code to execute at a specific time

Essentially I want to have a DateTimeOffset and execute code specifically at that date/time. What would be the best way to do this? I feel like timers would be a rather fragile approach.
Becquerel
Becquerel10/3/2022
depends how involved you wanna get
Becquerel
Becquerel10/3/2022
i've used quartz for this and it worked well, and seen hangfire mentioned as a simpler alternative
thinker227
thinker22710/3/2022
I would like at least an accuracy within a minute, so not very high standards
thinker227
thinker22710/3/2022
Are Quartz and Hangfire libraries or something?
Becquerel
Becquerel10/3/2022
yeah
Becquerel
Becquerel10/3/2022
quartz is the 'can do literally anything if you tinker with it enough' type
thinker227
thinker22710/3/2022
Is it easy-ish to set up?
Becquerel
Becquerel10/3/2022
it uses its own terminology for stuff but not tooooo bad
Becquerel
Becquerel10/3/2022
you create a class to define your job and another for any data you want to pass along, were the main things
thinker227
thinker22710/3/2022
Doesn't sound too bad
thinker227
thinker22710/3/2022
I'm planning to use this for a background service, is there anything which I should be aware of in relation to that?
Becquerel
Becquerel10/3/2022
i don't think so - from what i remember that was one of its primary use-cases
thinker227
thinker22710/3/2022
nice
thinker227
thinker22710/3/2022
@234678959491645440 Do you happen to have any good tutorial/resource on using Quartz?
Becquerel
Becquerel10/3/2022
no, sorry
Becquerel
Becquerel10/3/2022
it was a year ago i last used it
thinker227
thinker22710/3/2022
Quartz seems almost waaay to overkill for this. I literally just want to schedule something for a single time. The Quartz documentation makes it seem unnecessarily difficult to do this.
Message Not Public

Sign In and Join Server To See

10/3/2022
Ezlanding
Ezlanding10/3/2022
Random question:
Is a “daemon” a correct way to refer to a background service like that? I’ve seen the term being used without much explanation before
thinker227
thinker22710/3/2022
literally no idea what that is
Ezlanding
Ezlanding10/3/2022
thinker227
thinker22710/3/2022
that image scares me
Message Not Public

Sign In and Join Server To See

10/3/2022
Ezlanding
Ezlanding10/3/2022
So not just any background process then
Message Not Public

Sign In and Join Server To See

10/3/2022
thinker227
thinker22710/3/2022
I mean like annoying to use. Ideal would being able to just schedule an action for a specific time. Although I suppose I could just create a wrapper class/service around a timer.
thinker227
thinker22710/3/2022
Wasn't there supposed to be a new fancy timer in .NET 6?
Message Not Public

Sign In and Join Server To See

10/3/2022
thinker227
thinker22710/3/2022
I want to do stuff other than just schedule events in the app
Message Not Public

Sign In and Join Server To See

10/3/2022
thinker227
thinker22710/3/2022
Also the fact this mentions COM doesn't bode well
Message Not Public

Sign In and Join Server To See

10/3/2022
Message Not Public

Sign In and Join Server To See

10/3/2022
thinker227
thinker22710/3/2022
Fair I guess
thinker227
thinker22710/3/2022
Again I can just wrap it in a class/service
Message Not Public

Sign In and Join Server To See

10/3/2022
Message Not Public

Sign In and Join Server To See

10/3/2022
Auger
Auger10/3/2022
thinker227
thinker22710/3/2022
What's this "Cron" thing that keeping popping up in documentation?
Auger
Auger10/3/2022
It's a pattern that specifies a time-based schedule
Auger
Auger10/3/2022
thinker227
thinker22710/3/2022
huh, neat
Auger
Auger10/3/2022
Very
Auger
Auger10/3/2022
Alternatively, if you're executing in the context of a Linux machine, setting up a CRON tab that just executes your program at a regular interval might be easier
Auger
Auger10/3/2022
crontab -e
Auger
Auger10/3/2022
This similar to Windows task scheduler, except Windows doesn't use Cron patterns
thinker227
thinker22710/3/2022
To be fair, the thing I wanna make isn't much more complex than a background service which shuts down the system at specific times and also does some Windows toast interaction, but still I thought this would be a decent opportunity to learn about hosted services and stuff
Auger
Auger10/3/2022
So if this is a hosted service that you want running constantly, I would recommend my first post, but if it's something that can just be a spawned process every now and then and doesn't have to be constantly running, perhaps something like Cron tab or task scheduler is relevant
thinker227
thinker22710/3/2022
You mean NCrontab?
Auger
Auger10/3/2022
Yeah, just a simple library that yields a time until the next scheduled moment to do something.

For that project type I'd probably use a WorkerService
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy