question

melonNG-6986 avatar image
0 Votes"
melonNG-6986 asked melonNG-6986 commented

How can I make a task to run once?

I want to achieve this:

When my website is published by webdeploy/started/restarted, the website automatically run a task to send a post method to another site.

How can I create a task only run once?

It seems hangfire can't do this.

dotnet-aspnet-core-generaldotnet-aspnet-core-mvcdotnet-aspnet-core-webapi
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @melonNG-6986 Could you please tell me what you mean about create a task only run once? Normally, we could run some command by modifying the publish profile or else to run some cmd command. But you mean after you set it, you just want to run this task only once? If we republish this application, you don't want to run this task again?

0 Votes 0 ·

I want to task running in the back-end but not by modifying the publish profile or some cmd command that is running by a third-party program.

Every time I republished/restart my project, the task will run. It is used to tell the remote sites to clear the old cache and cache new data from my website.

0 Votes 0 ·

In my opinion, you want to achieve your requirement, I suggest you could consider using the third-party program to publish your application. For example, you could use web deploy command to publish your web site instead of using visual studio. Since visual studio publish doesn't contains this feature to trigger something when publish unless modify the csproj or publish profile.

0 Votes 0 ·

1 Answer

Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered melonNG-6986 commented

just put the call in startup.cs use async task, and don't await as you want to fire and forget.








· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

It sounds great! Thank you so much!

0 Votes 0 ·