How to execute task in certern time every day?

mc 4,026 Reputation points
2022-12-06T09:29:02.637+00:00

I want run a function at certern time everyday .

the programe is loop and will check every 1 minutes.

I will read record in database and get one time such as "08:00" for another is "09:00"

and I want to run function when it is "08:00" or it is "09:00" once.

then I will sleep(60*1000) (1 minutes)

how to do it?

do not miss it and do not run twice?

.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
326 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,573 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Sreeju Nair 12,181 Reputation points
    2022-12-06T16:29:26.597+00:00

    You can create background tasks in ASP.Net Core to execute services in the background. Refer to the following article to understand more about this.

    https://weblogs.asp.net/sreejukg/running-background-tasks-in-asp-net-applications

    Ideally speaking, I recommend you look into Azure functions. "Azure functions" is a serverless solution that will help you to write, deploy and manage your functions easily.

    https://video2.skills-academy.com/en-us/azure/azure-functions/functions-overview


  2. Karen Payne MVP 35,291 Reputation points
    2022-12-08T12:59:52.96+00:00

    I recommend working with Quartz library which takes time to master. Check out the documentation and FAQ's.

    Couple Quartz with say a SQL-Server database (see sample scripts) where one table is for telling your code designed with Quartz when to run, did it run. Then add logging (which is part of the library or use your own library) to text file and perhaps sending email messages on successful run.

    0 comments No comments