asp.net web api - Timer event in web api -


i have created timer event try running in background of web api, found works fine when debugger on local dev machine. however, timer not work when added them iis on server. stops after first web request finishes( tested writing text log files, seems stopped after few triggers, once web request completed) here example code.

void refreshtimestart()     {         refreshtimer = new system.timers.timer(convert.toint32(configurationmanager.appsettings["timer_interval"]));         refreshtimer.elapsed += new elapsedeventhandler(connectionresetevent);         refreshtimer.autoreset = true;         refreshtimer.enabled = true;     } void connectionresetevent(object source, elapsedeventargs e)     {         testindex = testindex + 1;         writetofile(testindex);                } static void writetofile(int i)      {          string text = "this start trigged. ";          system.io.file.writealltext(@"c:\projects\abc" + i.tostring() + ".txt", text);      } 

any idea of how achieve this? lot.

the question asked long time ago here's answer anyway.

first of all, using timer in web api not best idea. windows service more appropriate. being said, problem must come 2 issues:

  1. a web api awaits request , initializes after first request. you'll have initiate request timer start.
  2. the default settings of application pools in iis have timeout. if initialize web api, application pool terminate after timeout period has elapsed. disable timeout.

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -