I need to run a scheduled task every new day in the main asp.net mvc application. Can I do it and how ?!
Thnx
DotNet Core 2 introduces a new interface IHostedServicethat takes care of background tasks.
IHostedService
Here you will have some examples of how to deal with scheduled tasks.
https://blog.maartenballiauw.be/post/2017/08/01/building-a-scheduled-cache-updater-in-aspnet-core-2.html
https://blogs.msdn.microsoft.com/cesardelatorre/2017/11/18/implementing-background-tasks-in-microservices-with-ihostedservice-and-the-backgroundservice-class-net-core-2-x/
.
, Quarz, Hangfire Azure WebJobs, ASP.NET Core.
, Quarz Hangfire ASP.NET Core, , , IIS Azure , , IIS (- - ), (IIS , - ).
, , IIS - . , ASP.NET Core ( , Azure Azure Web Jobs).
Startup.cs System.Threading.Timer.
// add the below into your Startup contructor public Startup(IHostingEnvironment env) { // [...] var t = new System.Threading.Timer(doSomething); // do something every 15 seconds t.Change(0, 15000); } // define a DateTime property to hold the last executed date public DateTime LastExecuted { get; set; } // define the doSomething callback in your Startup class private void doSomething(object state) { System.Diagnostics.Debug.WriteLine("The timer callback executes."); // this callback is called every 15 seconds // but the condition below makes sure only it // only takes place at 17:00 // every day, when LastExecuted is not today if(DateTime.UtcNow.Hour == 17 && DateTime.UtcNow.Minute == 0 && DateTime.UtcNow.Date != LastExecuted.Date) { LastExecuted = DateTime.UtcNow; System.Diagnostics.Debug.WriteLine("#### Do the job"); } }
powershell script, GET api/endpoint . , Windows .NET Core Application.
1. powershell script myjob.ps1
$url="http://www.myapp.com/api/runjob" $content=(New-Object System.Net.WebClient).DownloadString("$url"); $Logfile = "D:\Temp\job.log" Add-content $Logfile -value $content
2. powershell
Powershell :
Set-Executionpolicy -Scope CurrentUser -ExecutionPolicy UnRestricted Set-Executionpolicy -Scope Process -ExecutionPolicy UnRestricted
: https://www.metalogix.com/help/Content%20Matrix%20Console/SharePoint%20Edition/002_HowTo/004_SharePointActions/012_SchedulingPowerShell.htm
3. script
Task Schedulerer. " "
Program: Powershell Argument: -noprofile -executionpolicy bypass -file "C:\Jobs\myjob.ps1"
Azure, . Azure WebJobs URL-, , cronjob, , . asp.net, . , VS .
For example, let it listen in on a queue and send an email when something is queued. Or create a thumbnail of a large image.
Mor info can be found here: https://azure.microsoft.com/en-us/documentation/articles/websites-dotnet-webjobs-sdk-get-started/
Use the features of Azure. That's what it was built for. This is pretty cool.
https://docs.microsoft.com/en-us/azure/azure-functions/functions-overview
Source: https://habr.com/ru/post/1657809/More articles:Анимация UIScrollView вправо - uiviewcontrollerTomcat max connections for each context - javaMaven jar plugin changes file names (coding errors) - javaHow to fill in field fields having the same class - clojureJNA: use one thread for all callbacks - javaWhat are the best ways to prevent duplication with Redux? - javascript.Net Core Slow after downtime - asp.net-coreXcode Storyboard does not update Designables custom class - xcodeHandling global exceptions in MVVM - c #Why does a reliable jms subscriber require both a client identifier and a subscriber name? - jmsAll Articles