简体   繁体   English

显示长时间运行过程的进度

[英]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.

相关问题 在Winforms中显示模式加载窗口以长时间运行 - Show modal loading window in Winforms for long-running process 异步/等待具有进度/取消的长时间运行的API方法 - Async/await for long-running API methods with progress/cancelation 在长时间运行过程中禁用鼠标点击? - Disable mouse clicks during long-running process? 返回之前,先使用DBContext Access启动长时间运行的进程 - Start Long-Running Process With DBContext Access Before Returning IIS进程之外的长期运行的存储过程 - Long-running stored procedure out of IIS process 关闭Windows服务中的长时间运行的进程 - Shutting down a Long-running process in a Windows Service 在长时间运行的过程中,使用ReactiveUI,Observables,SubscribeOn和ObserveOn在UI中显示输出日志 - Using ReactiveUI, Observables, SubscribeOn, and ObserveOn to display an output log in UI during a long-running process 如何防止NHibernate长时间运行的进程锁定网站? - How to prevent NHibernate long-running process from locking up web site? 使用 ReSharper,如何在长时间运行的单元测试期间显示调试输出? - Using ReSharper, how to show debug output during a long-running unit test? 具有取消功能的长时间运行模式 - Pattern for long-running operation with cancellation ability
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM