Trying to run methods after api starts up

Viewed 60

So I've written an api on ASP.Net-Core and I want to run some csvReader methods as soon as the server starts. Currently it just starts up and doesn't run my DataMigrationController.

class Program
{
    public const string _path =
        "C://path";

    static void Main(string[] args)
    {
        
        CreateWebHostBuilder(args)
            .UseUrls("https://localhost:44301/")
            .Build()
            .Run();

        DataMigrationController DMC = new DataMigrationController();
        DMC.readCSV(_path);
        Console.WriteLine("Done");
    }

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>();
}
2 Answers

From the docs, it appears as if the Run() method is blocking; you would want to use Start() instead.

Related