I want to create an Asp MVC application to run a code every 12 hours. This code will create a file on the server each time.
So I've made an async method and called it from Application_Start
event to make a schedule and It worked fine.
My problem is where I want to create the file. As I call my method from Application_Start
, the instance of Server.MapPath
is not available there. So I moved my calling code into Application_AuthenticateRequest
. But the problem was still here, this time because of my async method that doesn't allow using the Server.MapPath
.
What is the solution to do all of these in MVC.net:
- Create a method which is called every 12 hours
- Create async method to avoid locking application on application_start
- Create a file on each call