I am trying to build a website. At a p开发者_高级运维articular time, daily, say 6pm, a scheduled task runs. How should i say, "pause" users who are viewing my site, and show them the progress of the scheduled task that is being executed, say in the form of a jquery ui progress bar, like "task starting", "task executing", "task terminating"...
As I feel for the scheduling task go for the windows service rather than go for the schedular in your application. by this way you can easily manage the things and you can also poll satus for your user without freezing your hosted web site.
check this will help you
Combine Web and Windows Services to Run Your ASP.NET Code at Scheduled Intervals
It's a lot easier if you know the event happens at an exact time. Otherwise, you'd need to poll the server periodically to see if said task was running.
But if you know it happens at an exact time, I would pass a variable from a server-side scripting language that contains the server time to JavaScript (as you can't rely on the the client-side clock).
Then you calculate the amount of time until the next time the task execution occurs, and use setTimeout()
to trigger a function that will obscure the website content and overlay a jQuery UI progress bar.
Finally, you then begin to poll to server every so often to check the progress of the task, updating the progress bar as needed.
I think if I were to get into the nitty gritty specifics, my answer would span at least a few questions, so I hope a broad overview is helpful.
ADDENDUM
By "span at least a few questions", I mean that your question should really be separated into multiple questions. 1) How do I "pause" users on a website when a task occurs, 2) How do I obscure the website's content with an overlay, and 3) How do I use the jQuery UI progress bar widget.
As to how to obsure the content... if you don't need to worry about mobile clients (i.e., clients that don't support position: fixed
, you just need to do something like:
$('<div id="overlay" style="position: fixed; top: 0; left: 0; height: 100%; width: 100%; background-color: #000;"></div>')
.css("opacity", 0.5).appendTo("body");
Then you'd position the progress bar widget on top of the overlay.
精彩评论