.Net Core 2.1 Reporting progress of long task
Asked Answered
D

2

7

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.

Several of the functions are long-running tasks. One example is an import of an address gazetteer CSV file. The files are typically 50-100Mb in size and need parsing. I have written an uploader and import function, which runs in around 15 minutes - most of that is database write-time.

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.

I've looked at IHostedServices and the BackgroundService functions, but I cannot find any examples that match what I'm trying to do. 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.

Can anyone point me to a good .Net Core > 2.0 example of something like this?

Thanks in advance.

Diligent answered 23/7, 2018 at 14:34 Comment(0)
A
4

For a long running process, you could use widely used Hangfire

Progress tracking via SignalR is described in the documentation : http://docs.hangfire.io/en/latest/background-processing/tracking-progress.html

It is compatible with .Net Core 2.1.

Alongshore answered 23/7, 2018 at 14:54 Comment(0)
R
0

Personally, I'd write a Windows service to do the processing using something like 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. Add an endpoint (maybe with something like Nancy: http://nancyfx.org/) which your ASP app can call to retrieve the progress information.

Radborne answered 23/7, 2018 at 15:6 Comment(1)
But .Net Core is OS-agnostic. It's self-defeating to then tie it to Windows..Rocca

© 2022 - 2024 — McMap. All rights reserved.