Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can enqueue requests into a Queue in memory and you can send them to a database periodically with use of Quartz .Net. You can simply make this in Global.asax.cs as follows:</p> <pre><code>public class RequestQueue { private readonly Queue&lt;HttpRequest&gt; _requestHistory; private RequestQueue() { _requestHistory = new Queue&lt;HttpRequest&gt;(); } private static RequestQueue _singleton; public static RequestQueue Instance() { if (_singleton == null) _singleton = new RequestQueue(); return _singleton; } public void Enqueue(HttpRequest request) { _requestHistory.Enqueue(request); } public void Flush() { while (_requestHistory.Count &gt; 0) { var request = _requestHistory.Dequeue(); try { //Write request To Db } catch (Exception) { _requestHistory.Enqueue(request); } } } } public class WebApiApplication : System.Web.HttpApplication { public WebApiApplication() { base.BeginRequest += delegate { RequestQueue.Instance().Enqueue(HttpContext.Current.Request); }; } private void InitializeQuartz() { ISchedulerFactory sf = new StdSchedulerFactory(); IScheduler sched = sf.GetScheduler(); DateTimeOffset runTime = DateBuilder.EvenMinuteDate(DateTime.UtcNow); DateTimeOffset startTime = DateBuilder.NextGivenSecondDate(null, 5); IJobDetail job = JobBuilder.Create&lt;QueueConsumer&gt;() .WithIdentity("job1", "group1") .Build(); ITrigger trigger = TriggerBuilder.Create() .WithIdentity("trigger1", "group1") .StartAt(runTime) .WithCronSchedule("5 0/1 * * * ?") .Build(); sched.ScheduleJob(job, trigger); sched.Start(); } public class QueueConsumer : IJob { public void Execute(IJobExecutionContext context) { RequestQueue.Instance().Flush(); } } protected void Application_Start() { InitializeQuartz(); </code></pre>
    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.
    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