Reputation: 1
I'm attempting to run windows scheduler task using dotnet core 2.0. the problem is that I have to specify the IIS localhost port to perform the task showing in below code.
I want to perform task without using ".UseUrls("http://localhost:8089")" code.
public class Program
{
public static void Main(string[] args)
{
var pathToExe = Process.GetCurrentProcess().MainModule.FileName;
var pathToContentRoot = Path.GetDirectoryName(pathToExe);
var host = WebHost.CreateDefaultBuilder(args)
.UseContentRoot(pathToContentRoot)
.UseUrls("http://localhost:8089")
.UseStartup<Startup>().Build();
host.RunAsCustomService();
}
}
Upvotes: 0
Views: 2699
Reputation: 180
I suggest you use background tasks with hosted services instead of windows scheduler. You will break the cross-platform compatibility of your asp.net core app since windows task scheduler is only available in Windows OS. You can check these articles if you're interested in hosted services: Background tasks with hosted services in ASP.NET Core & Building a scheduled task in ASP.NET Core/Standard 2.0
Upvotes: 1