Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>While doing this on a website is not ideal or recommended..it is possible, given that the site is <strong>always running.</strong></p> <p>Here's a sample: I'm creating a Cache item in the global.asax with an expiration. When it expires, an event is fired. You can run your reports or whatever in the OnRemove() event.</p> <p>Then you can set a call to a page(preferably a very small one) that will trigger code in the Application_BeginRequest that will add back the Cache item with an expiration.</p> <p>global.asax</p> <pre><code> private const string VendorNotificationCacheKey = "VendorNotification"; protected void Application_Start(object sender, EventArgs e) { //Set value in cache with expiration time CacheItemRemovedCallback callback = OnRemove; //Expire after 15 minutes Context.Cache.Add(VendorNotificationCacheKey, DateTime.Now, null, DateTime.Now.AddMinutes(15), TimeSpan.Zero, CacheItemPriority.Normal, callback); } private void OnRemove(string key, object value, CacheItemRemovedReason reason) { SendVendorNotification(); //Need Access to HTTPContext so cache can be re-added, so let's call a page. Application_BeginRequest will re-add the cache. var siteUrl = ConfigurationManager.AppSettings.Get("SiteUrl"); var client = new WebClient(); client.DownloadData(siteUrl + "default.aspx"); client.Dispose(); } private void SendVendorNotification() { //Do Tasks here } protected void Application_BeginRequest(object sender, EventArgs e) { //Re-add if it doesn't exist if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("default.aspx") &amp;&amp; HttpContext.Current.Cache[VendorNotificationCacheKey] == null) { //ReAdd CacheItemRemovedCallback callback = OnRemove; Context.Cache.Add(VendorNotificationCacheKey, DateTime.Now, null, DateTime.Now.AddMinutes(15), TimeSpan.Zero, CacheItemPriority.Normal, callback); } } </code></pre> <p>This works well, if your scheduled task is quick. If it's a long running process..you definitely need to keep it <strong>out</strong> of your web app.</p> <p>I haven't had any problems or weird errors thrown with this method.</p>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      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