0

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:

  1. Create a method which is called every 12 hours
  2. Create async method to avoid locking application on application_start
  3. Create a file on each call
Heimi
  • 126
  • 1
  • 12
Siamak Ferdos
  • 3,181
  • 5
  • 29
  • 56
  • Why not create a windows service? you can easily create a schedule for the service. – Nkosi Dec 02 '17 at 11:28
  • @Nkosi Because my server is a shared server and I have not access to windows service – Siamak Ferdos Dec 02 '17 at 11:46
  • You can make a thread in application_start that calls a service or api every 12 hours and that api/service maps the File to the server – IbraHim M. Nada Dec 02 '17 at 11:47
  • @IbraHimM.Nada I think it will work by your solution. However, I should make a separate project for this. If I can't find better one, I will use this. Thanks – Siamak Ferdos Dec 02 '17 at 11:55
  • 1
    MVC is the completely wrong way to do this. At best it will be unreliable. Can you use Azure Functions? If you are calling it only every 12 hours the entire thing would probably be completely free. – Crowcoder Dec 02 '17 at 12:12

0 Answers0