简体   繁体   中英

.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.

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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