Jay Panchal
Jay Panchal

Reputation: 1

ASP.NET Core windows scheduled task

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

Answers (1)

Wendell
Wendell

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

Related Questions