Firing events on regular time intervals (coming from database) using ASP.Net C#

狂风中的少年 提交于 2019-12-25 11:35:12

问题


Please check the image below.

Below I have a simple lottery system where I have these columns,

  1. Vistors : Total no visitors till date
  2. Next DrawTime : Will come from database (no problem with this)
  3. TodayDate : Current IST Date(noproblem with this)
  4. CurrentTime: Current IST time with seconds ticking like clock.
  5. Result
  6. TimeToDraw : Here we have main problem. Here we need is again ticker with minutes and seconds. For example if its get 15mins from db then the field will display 15:00 and on each second it will get decremented like 14:59,14:58... and so on. when the timer reach zero 00:00, i need to execute some server side code that will draw the result based on data saved in db, without reloading the entire page.

I am feeling lost. Please help me.

I have tried few links , but did'nt get any satisfactory result. Here are the links

Call js-function using JQuery timer

http://r4r.co.in/asp.net/01/tutorial/asp.net/How%20to%20make%20CountDown%20Timer%20in%20ASP.NET%20Using%20c-sharp.shtml

Javascript event triggers based on local clock

How to periodically update server-side value on webpage?

Requirements (Update):

  1. Implementation of Minutes:Second(MM:SS) ticker using server side or client side scripts.
  2. How to fire event when the ticker reaches zero(00:00)?
  3. Again after drawing result, ticker will get reset to 15 min/30 min or whatever coming from database.

Please I need purely ASP.Net and C# (if possible) code. Any reference or link will be higly appreciated. Thanks in Advance


回答1:


Do NOT poll the server every second, that will create too much unneeded trafic.

Put a timer in the page (javascript) and when the timer reaches 0 poll the server.

The server should keep track of the time by itself; not relying on the client to provide the (potentially spoofed) time and pass back the appropriate response either winning tickets or nothing if it's not time yet to draw.

If you really need/want to push information from a server to the clients I recommend having a look at the suggestions here: https://stackoverflow.com/questions/6883540/http-server-to-client-push-technologies-standards-libraries

For SignalR have a look at this sample it is very close to what you need.

Do NOT use server side code to update the time on webpage unless it is critical.

For the countdown script look at the answer to this question: Javascript Countdown

When the timer reaches zero, refresh the page or execute an Ajax call using jQuery. When the call returns update the page depending on the server's response.

If you need more explicit answers you need to show what you have tried and point out problems you are having.



来源:https://stackoverflow.com/questions/16354306/firing-events-on-regular-time-intervals-coming-from-database-using-asp-net-c-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!