title: Add timer method to asp.net core 3.1 startup
body: <p>I want to set a Timer to a method, so its called every, say, 10 minutes, while the application is running.</p>
  <p>I have read up on it, but I haven't found an example, where it seems to have the same configuration/start up settings and the time tutorials mostly work with a main method, so I haven't figured out yet, which services I have to add to my startup and/or where to put my time and method.</p>
  <p>So I would set my timer like <a href="https://docs.microsoft.com/de-de/dotnet/api/system.threading.timer.-ctor?view=netcore-3.1" rel="nofollow noreferrer">here</a>:</p>
  <pre><code>var stateTimer = new Timer(MyMethod, null, 1000, 600000); //any way to change miliseconds to minutes here?
  </code></pre>
  <p>and then write my method like:</p>
  <pre><code>static void MyMethod
  {
   //all the code I want to execute every 10 minutes
  }
  </code></pre>
  <p>This is my Startup:</p>
  <pre><code>public class Startup
      {
          public Startup(IConfiguration configuration)
          {
              Configuration = configuration;
          }
  
          public IConfiguration Configuration { get; }
  
         
          public void ConfigureServices(IServiceCollection services)
          {
              services.AddControllersWithViews();
              //....
  
          }
  
          
          public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
          {
              if (env.IsDevelopment())
              {
                  app.UseDeveloperExceptionPage();
              }
              //...        
          }
      }
  }
  </code></pre>
  <p>So where do I put the time and the method? If someone has an example using the same structure of startup, etc. it would be greatly appreciated. I have found for example <a href="https://forums.asp.net/t/2051633.aspx?Run+a+piece+of+code+once+a+day+automatically+in+asp+MVC" rel="nofollow noreferrer">this</a>, but it's different from my setup.</p>