.NET服务器如何将文件处理状态推送到客户端? [英] How can a .NET server push file processing status to client side?

查看:68
本文介绍了.NET服务器如何将文件处理状态推送到客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HTML页面,可以将file.txt上传到.NET / C#服务器。我正在尝试让服务器在处理文件中的每一行时将状态发送回客户端。任何人都可以指导我如何使用jQuery,AJAX和C#完成这项工作?



不幸的是我没有代码,因为我完全不知道如何开始。

I have an HTML page that uploads a file.txt to a .NET/C# server. I'm trying to have the server send a status back to the client as each line in the file is being processed. Can anyone guide me as to how this is done using jQuery, AJAX, and C#?

Unfortunately I have no code since I have absolutely no idea how to start.

推荐答案

您可以尝试 SignalR [ ^ ]。



有了这个,您可以通知客户任何服务器端更新。
You can try SignalR[^].

With this, you can notify the clients about any server side updates.


Web服务器(HTTP)不会向客户端推送任何内容。模型是客户端发出请求,服务器填写请求。服务器,至少是HTTP服务器,根本无法启动推送到客户端。



有两种选择。第一个是使用SignalR来促进通信(不通过HTTP!)。



第二个是客户端发送的东西要处理到网络服务器。 Web服务器代码启动某种进程或线程任务来处理作业。这个过程会在一些结构中公开进度信息,这些结构会随着时间的推移而更新。



现在,为了让客户获得进展,它必须定期发送请求到服务器询问这份工作怎么样?。 Web服务器将从作业结构中获取数据并将该数据发送回客户端,从而允许它显示进度。
Web servers (HTTP) do not push anything to the clients. The model is client makes a request, server fills the request. The server, at least a HTTP server, has no facility at all to initiate a push to a client.

There are two options. The first one is to use SignalR to facilitate the communication (which does NOT go over HTTP!).

The second is the client sends the stuff to process to the web server. The web server code launches some kind of process or threaded Task to process the job. This process would expose progress information in some structure that is updated as it goes.

Now, for the client to get the progress, it would have to periodically send a request to the server asking for "how is this job going?". The web server would get the data from the job structure and send that data back to the client, allowing it to display the progress.


这篇关于.NET服务器如何将文件处理状态推送到客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆