简体   繁体   English

.Net Core 2.1报告长期任务的进展情况

[英].Net Core 2.1 Reporting progress of long task

I am in the midst of re-writing a very old VB legacy application into a browser based C# ASP.Net application using Core 2.1 and Entity Framework back-ended to SQL server. 我正在将一个非常古老的VB遗留应用程序重新编写到基于浏览器的C#ASP.Net应用程序中,该应用程序使用Core 2.1和Entity Framework后端到SQL服务器。

Several of the functions are long-running tasks. 其中一些功能是长时间运行的任务。 One example is an import of an address gazetteer CSV file. 一个例子是导入地址地名词典CSV文件。 The files are typically 50-100Mb in size and need parsing. 这些文件的大小通常为50-100Mb,需要解析。 I have written an uploader and import function, which runs in around 15 minutes - most of that is database write-time. 我编写了一个上传器和导入函数,它运行大约15分钟 - 大部分是数据库写入时间。

I am trying to find a way to run the import process so that it can report back progress to the client browser, ideally by changing the menu option to a progress bar until the task is done - since the _layout.cshtml is on every page, it would let any user know the task is running and when it will finish. 我正在尝试找到一种方法来运行导入过程,以便它可以向客户端浏览器报告进度,理想情况下,通过将菜单选项更改为进度条直到任务完成 - 因为_layout.cshtml在每个页面上,它会让任何用户知道任务正在运行以及何时完成。

I've looked at IHostedServices and the BackgroundService functions, but I cannot find any examples that match what I'm trying to do. 我查看了IHostedServices和BackgroundService函数,但我找不到任何与我想要做的匹配的示例。 I've seen an article around MVC5 that used SignalR & Knockout (which I'm less familiar with) but it doesn't use the Core 2+ or the newer service functions. 我见过一篇关于MVC5的文章,它使用了SignalR&Knockout(我不太熟悉),但它没有使用Core 2+或更新的服务功能。

Can anyone point me to a good .Net Core > 2.0 example of something like this? 任何人都可以指向一个好的.Net Core> 2.0这样的例子吗?

Thanks in advance. 提前致谢。

For a long running process, you could use widely used Hangfire 对于长时间运行的过程,您可以使用广泛使用的Hangfire

Progress tracking via SignalR is described in the documentation : http://docs.hangfire.io/en/latest/background-processing/tracking-progress.html 文档中描述了通过SignalR进行的进度跟踪: http//docs.hangfire.io/en/latest/background-processing/tracking-progress.html

It is compatible with .Net Core 2.1. 它与.Net Core 2.1兼容。

Personally, I'd write a Windows service to do the processing using something like Topshelf: http://topshelf-project.com/ 就个人而言,我会编写一个Windows服务来使用Topshelf之类的东西进行处理: http//topshelf-project.com/

So, your ASP app calls that process with whatever data needs to be processed and it goes off and does it. 因此,您的ASP应用程序会调用该进程,无论需要处理哪些数据,它都会启动并执行此操作。 Add an endpoint (maybe with something like Nancy: http://nancyfx.org/ ) which your ASP app can call to retrieve the progress information. 添加一个端点(可能与Nancy: http//nancyfx.org/一样 ),您的ASP应用程序可以调用该端点来检索进度信息。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM