[英]Show progress on long-running process
I have a few server-side processes that can take very long times to run (30-60m). 我有一些服务器端进程可能需要很长时间才能运行(30-60米)。 These are a result of calling a web API from my webserver, and throttling the requests to match the maximum request rate of the service.
这些是从我的网络服务器调用Web API并限制请求以匹配服务的最大请求率的结果。
I want to be able to display the progress of this on the client, how can I go about doing this? 我希望能够在客户端上显示此进度,我该怎么做呢? Where do I start?
我从哪里开始?
Previous answers have hinted at SignalR, but that does not seem to be a thing with Asp.Net Core. 以前的答案暗示了SignalR,但这似乎与Asp.Net Core不相符。
Edit: It looks like SignalR is a thing with Asp.Net core. 编辑:看起来SignalR是Asp.Net核心的东西。 As this is the case, I have a followup question:
在这种情况下,我有一个后续问题:
I'm using AngularJS and managing the client-side state via AJAX requests to API endpoints. 我正在使用AngularJS并通过对API端点的AJAX请求来管理客户端状态。 Are there any potential coding or performance "gotchas" when trying to also utilize SignalR in conjunction?
在尝试同时使用SignalR时是否有任何潜在的编码或性能“陷阱”?
Additionally, are there alternatives that don't add SignalR as a dependency? 另外,有没有将SignalR作为依赖项添加的替代方案? It looks like it requires a beta-version of .Net Core, I'd rather stay in stable-release-land if at all possible.
看起来它需要一个beta版的.Net Core,如果可能的话,我宁愿留在稳定版本的土地上。
You can use SignalR and the IProgress interface to handle this. 您可以使用SignalR和IProgress接口来处理此问题。 The basic implementation is something like this:
基本实现是这样的:
Server-side 服务器端
[HubName("messageHub")]
public class MessageHub : Hub // This is your server-side SignalR
{
public async Task Countdown(IProgress<int> progress) // This is your IProgress
{
// 60 second countdown for an example
// NOT TESTED
for (int i = 1; i <= 61; i += 1)
{
await Task.Delay(1000);
progress.Report(i);
}
}
}
Client-side 客户端
// Hub connection
//
var messageConnection = $.hubConnection(url);
var messageHub = messageConnection.createHubProxy('MessageHub');
$.connection.hub.logging = true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.