Note that there are some explanatory texts on larger screens.

plurals
  1. POCancel Long Running task
    primarykey
    data
    text
    <p>i have some quetions regarding Long Running Task that runs when application start. i have created a thread that Runs when asp.net application start in Global.asax(Application_Start) and i abort thread in Global.asax (Application_End) </p> <p>i want to replace thread with My Task . i have done this way</p> <p>Thread implementation </p> <pre><code>t = new Thread(new ThreadStart(() =&gt; CheckConnection(emailTo, emailSubject, emailBody))); t.Start(); _logger.Info("DB Monitor Thread Started ThreadID: " + t.ManagedThreadId); </code></pre> <p>Task Implementation </p> <pre><code>Task.Factory.StartNew( state =&gt; { System.Web.HttpContext.Current = (HttpContext)state; CheckConnection(emailTo, emailSubject, emailBody); }, System.Web.HttpContext.Current ); </code></pre> <p>Check connection method basically Check that SQl Server is Live and Running or not after set interval and if it fails it send email. my questions are</p> <p>Check Connection Implementation </p> <pre><code>while (true) { Thread.Sleep(600000); using (EntityFMContextctx = new EntityFMContext()) { try { ctx.Connection.Open(); } catch (EntityException ex) { SendEmail(to, subject, body, ex); } } } </code></pre> <p><strong>Questions:</strong></p> <ol> <li><p>how can i cancel this task like we do Thread.Abort can we cancel this task too?</p></li> <li><p>do we need to Cancel task because when application End or Stop . didnt this Task will be cancelled or aborted automatically. Because application is Ended/Finished. </p></li> </ol> <p>Can some one guide me how to handle this scenario .any help will be appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload