简体   繁体   English

在服务器和客户端之间交流进度

[英]Communicate progress between server and client

I have a controller action which imports an uploaded excel file into a database. 我有一个控制器操作,它将上载的excel文件导入数据库。 The import can take several minutes. 导入可能需要几分钟。 How can I report the progress of the import to the client? 如何向客户报告导入进度? I know that I have to use ajax but I could not find any clean code which would be ideal to report a progress. 我知道我必须使用ajax,但找不到任何理想的报告进度的干净代码。

I am quite new to mvc4 and asp.net. 我对mvc4和asp.net相当陌生。 So I would like to hear your advices/approaches to solve my problem. 因此,我想听听您的建议/方法来解决我的问题。 I would like to write a solid and clean solution but I really don't know how to start. 我想写一个可靠的解决方案,但我真的不知道如何开始。

Would be very nice if anyone would have any experience in reporting the progress to the client. 如果有人在向客户报告进度方面有任何经验,那就太好了。

A simple method is to have the upload method (which begins the processing) return an ID for the job that is running. 一种简单的方法是使upload方法(开始处理)返回正在运行的作业的ID。 Then query the job status using that ID. 然后使用该ID查询作业状态。

I would strongly suggest to use plupload plugin. 我强烈建议使用plupload插件。 This plugin It works perfectly for all browsers and have progress bar 该插件对所有浏览器都完美运行,并具有进度条

If you are importing the data into MSSQL via a job, you can use a script to monitor the status of the job until it is complete. 如果要通过作业将数据导入MSSQL,则可以使用脚本来监视作业的状态,直到完成为止。 If the client needs to know the % of record imported, you could retrieve the number of rows to be imported from the excel sheet and compare it to the total rows in the table. 如果客户需要知道导入记录的百分比,则可以从excel工作表中检索要导入的行数,并将其与表中的总行进行比较。 You can then report back the percent of rows that have been imported. 然后,您可以报告已导入的行的百分比。

However, this can get tricky if it is not a simple import into a table, but multiple tables. 但是,如果这不是简单地导入到一个表中而是多个表,则可能会变得棘手。 In that case it would be up to you to figure out the expected number of rows added and monitor all of those against the current import. 在这种情况下,您将需要确定预期添加的行数,并根据当前导入监视所有这些行。

Once you figure that out, it wouldn't be too hard to supply a status bar back to the user based on the data returned. 一旦弄清楚了,就可以根据返回的数据向用户提供状态栏,这并不难。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在CE 6.0设备(作为服务器)和PC(作为客户端)之间进行通信 - How to communicate between CE 6.0 device (as server) and PC (as client) 如何在iis上的android客户端和c#服务器之间通信? - How can I communicate between android client and c# server on iis? 如何使用内存映射文件在同一台计算机上的服务器和客户端之间进行通信? - How do I communicate between a server and a client on the same computer using memory mapped files? 在node.js服务器和C#客户端之间进行通信的最佳方式是什么? - What is the best way to communicate between a node.js server and a C# client? 报告客户端/服务器环境中的进度 - Report progress in client/server environment 在客户端上显示服务器批处理进度 - Display server batch progress on client Signalr,客户端说已连接但无法通过服务器进行通信 - Signalr, client says connected but not able to communicate by server 将 OPCDA 客户端与 OPC UA 服务器通信 - Communicate OPCDA client with OPC UA server WCF与多个服务器进行客户端通信的方式 - WCF way to communicate client with multiple server Tcp服务器/客户端应用程序与其他PC进行通信 - Tcp Server/Client Application to communicate with other PCs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM