I have a ASP.NET MVC3 application that handles time-consuming processes (copying a large file from network). What we want to do is:
- User clicks a button to post the form to trigger the process
- Application starts a new thread to start copying the file
- Application shows a message saying the file-copying process has begun
- User can close the browser while the copying processed and finished in the background.
The idea is that the user doesn’t need any confirmation on the progress of the process, nor be notified when the process has completed.
We currently let the controller trigger an event in a Windows Service, and use the Windows Service to do the actual work. I’m wondering if there’s a better/cleaner way to do this?
You could use System.Threading.Tasks.Task calling the StartNew method with an Action delegate.
Using those tools your controller would look something like this:
Another option is you could use System.Reactive.Concurrency and the IScheduler interface with TaskPoolScheduler as the concrete implementation to perform the action (possibly injected in the controller constructor.
As a benefit, if you do it this way you can use TestScheduler as the implementation of the interface when you are unit testing.