Create a routine within an Asp net application in c#

Asked

Viewed 879 times

4

I have to run a method on my project ASP.Net, made a screen for me to select a Excel and a method for handling and insertions in the bank, only that this method will have to be run daily, someone has some suggestion of how to do this?

PS.: I am a layman in the environment ASP.Net

  • You mean the method has to be called daily without user interaction?

  • Where the app will stay?

  • That @Marcusvinicius.

  • It is currently on the site @Ciganomorrisonmendez , but I already got a server to host the application.

2 answers

1

There is a service FREE called A Trigger, where you register and can schedule calls to a Webservice. You can schedule directly through the control panel of your own website or use a library that gives you the same features programmatically. You can, by code, schedule, pause and cancel call schedules to your web service. Here’s an example of how to schedule via C code#:

Download the library via nuget:

Install-Package ATrigger

Configure the routine call:

using ATriggerLib;

....
ATrigger.Initialize("YOUR_APIKey", "YOUR_APISecret"); // obtenha a APIKEY e o APISecret se cadastrando no site
// crie um dicionário com tags que serão usadas para identificar o seu serviço,
Dictionary<string, string> tags = new Dictionary<string, string>();
tags.Add("type", "teste");

// configura a chamada da rotina uma vez ao dia
ATrigger.Client.doCreate(TimeQuantity.Day(), "1", "http://www.examplo.com.br/rotina?algumacoisa", tags);

If you want to stop scheduling the call, use:

ATrigger.Client.doDelete(tags);

Or to only pause/resume scheduling:

 // pausar
 ATrigger.Client.doPause(tags);
 // retomar
 ATrigger.Client.doResume(tags);

Read more here.

  • That’s right, thank you very much!!!!

1

It is not advisable to schedule tasks within an ASP.NET application.

Appdomain can be recycled at any time, and when it does, all threads that are not connected to a request processing will be aborted. In other words, your scheduled task can be aborted at any time, resulting in errors and inconsistent status.

More details on: The Dangers of Implementing Recurring Background Tasks In ASP.NET.

I advise creating a new application console, and then using the Windows Task Scheduler to choose the peripherality/frequency with which it should be invoked.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.