1-) C# RMOS - web api timer kullanımı ve iis de sürekli çalışması Making ASP.NET application always running
kaynak : https://docs.hangfire.io/en/latest/deployment-to-production/making-aspnet-app-always-running.html
1. Adım

2. Adım

3. Adım

4. Adım

5. ADIM
public class HomeController : Controller { public ActionResult Index() { ViewBag.Title = "Home Page"; time(); return View(); } public static Timer aTimer = null; public void time() { try { if (aTimer != null) { aTimer.Dispose(); } aTimer = new System.Timers.Timer(); aTimer.Elapsed += (sender, e) => MyElapsedMethod(sender, e); aTimer.Interval = 15000; aTimer.Enabled = true; } catch (Exception ex) { } } FrontEntities frontDB=new FrontEntities(); private void MyElapsedMethod(Object source, ElapsedEventArgs e) { try { LoginController loginController = new LoginController(); GenelModel genelModel = new GenelModel(loginController); int rezMasterId = genelModel.getQueryInt("select top 1 Rez_Id from rez where Rez_R_I_H='I'", frontDB); var item = loginController.getLoginByRezId(rezMasterId.ToString()); } catch (Exception ex) { } } |
DİĞER BAKMASANDA OLUR
1. Adım
public class HomeController : Controller
{
public static TumuTimeController tumuTime=null;
public ActionResult Index()
{
if (tumuTime!=null && TumuTimeController.aTimer!=null)
{
TumuTimeController.aTimer.Dispose();
}
ViewBag.Title = "RESTORAN APİ ";
tumuTime = new TumuTimeController();
tumuTime.time();
return View();
}
2. Adım
public class TumuTimeController
{
public static Timer aTimer=null;
public void time()
{
try
{
if (tumuTime!=null && TumuTimeController.aTimer!=null)
{
TumuTimeController.aTimer.Dispose();
}
calistir("recdep");
aTimer = new System.Timers.Timer();
aTimer.Elapsed += (sender, e) => MyElapsedMethod(sender, e, ayarlar);
aTimer.Interval = 45000 ;
aTimer.Enabled = true;
}
catch (Exception ex)
{
}
}
private void MyElapsedMethod(Object source, ElapsedEventArgs e, entegreAyarlar ayarlar)
{
calistir(ayarlar.recDep);
}
public void calistir(string recDep)
{
// todo code
}