Correctly implement background process Thread in ASP.NET -


i need execute infinite while loop , want initiate execution in global.asax. question how should it? should start new thread or should use async , task or else? inside while loop need await taskex.delay(5000);

how do not block other processes , not create memory leaks?

i use vs10,asyncctp3,mvc4

edit:

 public void signalrconnectionrecovery()         {             while (true)             {                 clients.setconnectiontimestamp(datetime.utcnow.tostring());                 await taskex.delay(5000);             }         } 

all need run singleton instance globally long application available.

edit:solved

this final solution in global.asax

protected void application_start() {     thread signalrconnectionrecovery = new thread(signalrconnectionrecovery);     signalrconnectionrecovery.isbackground = true;     signalrconnectionrecovery.start();      application["signalrconnectionrecovery"] = signalrconnectionrecovery; }   protected void application_end() {     try     {         thread signalrconnectionrecovery = (thread)application["signalrconnectionrecovery"];         if (signalrconnectionrecovery != null && signalrconnectionrecovery.isalive)         {             signalrconnectionrecovery.abort();         }     }     catch     {             ///     } } 

i found nice article how use async worker: http://www.dotnetfunda.com/articles/article613-background-processes-in-asp-net-web-applications.aspx

and this: http://code.msdn.microsoft.com/csaspnetbackgroundworker-dda8d7b6

but think needs 1 perfect: http://forums.asp.net/t/1433665.aspx/1

asp.net not designed handle kind of requirement. if need run constantly, better off creating windows service.

update

asp.net not designed long running tasks. it's designed respond http requests. see cyborgx37's answer or can use threads carry out long-running jobs on iis? few reasons why.

update

now mentioned working signalr, see trying host signalr within asp.net, correct? think you're going wrong way, see example nuget package referenced on project wiki. example uses iasynchttphandler manage tasks.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -