简体   繁体   中英

Running a short-lived background task from MVC

I am coding an ASP.NET MVC 3 app. When a user logs in I need to check a remote system and get the latest data for that user from the system. This task will take approx 15 seconds.

The user should be able to enter my app straight after their login (not have to wait for 15s for the remote call!). When the remote call completes the users local information will be updated.

I was thinking of using a thread to do this, creating it after they have logged in and letting it run its course. However, after reading around, I am concerned about recycling etc when working with threads in MVC. I would use an async controller, but I dont need to feedback to the user the state of this background process. Am I right to be concerned about threads, even if they are short-lived?

" ...concerned about recycling... "

" ...don't need to feedback to the user the state... "

" ...short-lived... "

3 reasons why you should be using ThreadPool.QueueUserWorkItem .

Do not use "threads" in an web app. Let the server handle this by using "async" calls. Otherwise you would have to setup a threadpool and que the slow request.

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