Hello every I have faced an issue, I have created a background service in c# it's working but this service call when we start our project, But I want to call this service after running my server(Project) 10 min.
Loading
Hello every I have faced an issue, I have created a background service in c# it's working but this service call when we start our project, But I want to call this service after running my server(Project) 10 min.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh KumarPosted Apr 23, 2024, 7:14 AM
Hello Sunny,
Please refer this thread,
https://www.c-sharpcorner.com/blogs/explain-background-service-in-c-sharp
Abhishek YadavPosted Apr 24, 2024, 10:13 AM
try this in startup.cs
Kiran GirasePosted Apr 23, 2024, 8:37 AM
Hi Sunny,
To delay the start of your background service in C# after running your server (project), you can utilize a timer or a delayed task to achieve this. Here's a basic outline of how you can implement it:
1.Create a Timer: You can use a timer to wait for 10 minutes after your server (project) starts.
2.Start the Background Service: Once the timer expires, start your background service.
In this example:
YourServerclass represents your server (project).YourServeris created, it starts a timer with an initial delay of 10 minutes (TimeSpan.FromMinutes(10)).StartBackgroundServicemethod is called, which initializes and starts your background service.Sourabh DhimanPosted Apr 22, 2024, 6:55 AM
Jignesh it is not working, I started my project it's service run. Please check this startup.cs file code
(provider =>()));
services.AddHostedService
new CommonBackgroundService(dbConn,dbUserConn, provider.GetRequiredService
Jignesh KumarPosted Apr 22, 2024, 6:26 AM
Hello Sunny,
You can use in this way,
Sourabh DhimanPosted Apr 22, 2024, 5:53 AM
This is my code and I have registered this service in startup.cs file