Skip to content

Instantly share code, notes, and snippets.

@jhauge
Created September 6, 2016 08:15
Show Gist options
  • Save jhauge/75dc7355b5ce67e3ea0fd5af7bec7b3f to your computer and use it in GitHub Desktop.
Save jhauge/75dc7355b5ce67e3ea0fd5af7bec7b3f to your computer and use it in GitHub Desktop.
using System.Web;
using System.Web.Caching;
namespace DriftinfoSystem
{
public class Global : HttpApplication
{
private const string DummyCacheItem = "SimpleWindowsService";
private static CacheItemRemovedCallback _onCacheRemove;
protected void Application_Start(object sender, EventArgs e)
{
AddTask();
//AddTaskFetchDatabaseSync();
}
/// <summary>
/// This task emulates a scheduled windows service as explained here:
/// </summary>
private void AddTask()
{
_onCacheRemove = new CacheItemRemovedCallback(CacheItemRemoved);
HttpRuntime.Cache.Insert(DummyCacheItem, 120, null,
DateTime.Now.AddSeconds(120), Cache.NoSlidingExpiration,
CacheItemPriority.NotRemovable, _onCacheRemove);
}
public void CacheItemRemoved(string key, object value, CacheItemRemovedReason reason)
{
EmailAgent.TriggerAgent(true);
AddTask();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment