My team is developing an ASP.NET application, which among other things contains an import functionality. The import will typically be initiated by a user entering some settings in a web page, including the local file to be imported. When the user hits the “import” the file should be uploaded and then imported.
The import can be quite a lengthy operation, so it is not possible to do it directly from the aspx.cs code, it need to be done in some background way. Also it is important that once the file is uploaded, the import is not lost. I would also like the import to start immediately, not having to wait for a service or scheduled task that just checks for available work every X minutes.
What I’ve found as alternatives so far is:
- Background thread from ThreadPool or similar in ASP.NET. Will mostly work, but if the app pool is recycled the work is lost.
- Service with a timer that regularly checks a work table in the DB and runs the import. Will work, but either has the delay or causes very frequent requests for work from the DB.
- Service with a change notification query (don’t know the exact name, but it is possible to subscribe to changes from SQL server).
- Service getting work items through MSMQ.
- WCF service, hosted within a system service and not within ASP.NET to avoid recycling. Either the WCF service is called internally from ASP.NET or it is directly exposed and called from the client through AJAX (if a non-IIS-hosted WCF can expose AJAX endpoints).
Are there any other alternatives? Is there anyone with experience of the above alternatives?
You could have a windows service, which watches the upload directory for changes (e.g. using FileSystemWatcher).
That way, there would be no (or only minimal) delay until the service starts working and you don’t need any kind of polling from the service.
As for the settings (entered by the user): either store them in a DB (and query them from the service) or write them to a file as well.