Entity Infrastructure, Expectation of Results

I write code where, as a rule, query results from the Entity Framework are not returned. This query was sent using some jQuery code, and if I answer "no results", it will simply expand and repeat the same query - so I would not want to respond until any results are available, or a reasonable amount of time (for example , 30 seconds) has passed (however, I do not want to cache the results for 30 seconds - 30 seconds - this is a reasonable amount of time not to send a response to the request - if the results become available, I want them to be available "immediately")

How am I best to do this. I tried to sleep between the repeated request, but it does not work (every request that starts without any results, waits a full 30 seconds), and b) will bind the asp.net stream.

So, how do I convert my code so that I don't bind asp.net streams and respond as soon as the results are available?

[HttpGet] public ActionResult LoadEventsSince(Guid lastEvent, int maxEvents) { maxEvents = Math.Min(50, maxEvents); //No more than 50 using (var dbctxt = new DbContext()) { var evt = dbctxt.Events.Find(lastEvent); var afterEvents = (from et in evt.Session.Events where et.OccurredAt > evt.OccurredAt orderby et.OccurredAt select new { EventId = et.EventId, EventType = et.EventType, Control = et.Control, Value = et.Value }).Take(maxEvents); var cycles = 30; while (afterEvents.Count() == 0 && cycles-- > 0) { System.Threading.Thread.Sleep(1000); } return Json(afterEvents.ToArray(), JsonRequestBehavior.AllowGet); } } 
+3
source share
2 answers

check out this session 11: “ Pragmatic JavaScript jQuery and AJAX with ASP.NET .” At the very end (about 40-45 minutes per session), there is a demo version for you.
I'm sure you will say wow. Damian Edwards promised to talk more about technology on his blog, but we haven't seen it yet.

+4
source

See> Ajax comet / polling reverse implementation for ASP.NET MVC? .

You need to go through a long survey. It basically sends a request to the server, and the server just keeps it in the queue. It accumulates all requests, and as soon as it receives some data, it sends a response to each of the requests requested in the request queue.

EDIT : Also interesting> Implementing comets for ASP.NET?

0
source

All Articles