使用 Javascript 进行长流程的进度更新
我有一个 ASP.NET 页面,它调用一个 DLL,该 DLL 将启动一个更新产品信息的长进程。当流程运行时,我希望为用户提供有关该流程所在的产品以及产品状态的持续更新。我一直很难让它发挥作用。我将信息添加到日志文本文件中,我想我应该重定向到一个新页面,并让该页面使用 Javascript 每隔几秒从文本文件中读取一次。我的问题是有其他人尝试过这个并且效果好吗?
I have an asp.net page that calls a dll that will start a long process that updates product information. As the process is running, I want to provide the user with constant updates on which product that process is on and the status of the products. I've been having trouble getting this to work. I add information to a log text file and I was thinking that I'd redirect to a new page and have that page use Javascript to read from the text file every few seconds. My question is has anyone else tried this and does it work fairly well?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我将使用 Ajax 并轮询该文本文件以获取更新。
I would use Ajax and poll that text file for updates.
您可以将状态输出到数据库表,而不是将状态输出到基于文本的日志文件(或者,除了使用日志文件之外;您可以同时使用两者)。例如,按如下方式构造表:
现在您有一个队列。现在,当用户进入特定页面时,您可以执行以下两种操作之一:
您可以在发送行后将其从队列中删除,或者如果您想保留该数据,请添加另一个名为
sent
的列,并在发送后将其设置为true
用户已经看到该数据。Rather than outputting the status to a text based log file (or, in addition to using the log file; you can use both), you could output the status to a Database table. For example, structure the table as so:
So now you have a queue. Now when a user goes on a particular page, you can do one of two things:
You can delete the rows from the Queue after they've been sent, or if you want to retain that data, add another column called
sent
and set it totrue
once the user has seen that data.