Async fire and forget operation with callback

偶尔善良 提交于 2019-12-11 07:50:09

问题


I have an Mvc3 application with a forum area where questions can be posted also by e-mail.

The process for getting the emails from different accounts, parsing them and inserting in the db is really slow.

I thought at first to create a separate Windows Service with some scheduled process that would do all the separate email processing every few seconds.

I arrived to think that a better approach would be to initiate the email checking/parsing process when a user arrives in the forum section page. So the scenario would be:

  1. An user opens the page forum area in the mvc application
  2. An async process is initiated that will do all the slow stuff, the process could be initiated via a jquery/javascript call to a controller when the page is loaded.
  3. The controller would call the email parsing service and will return immediately (fire and forget).
  4. Every subsequent calls, also from other users to the same controller that initiate the email processing would be ignored during the work .
  5. When the process is finished, also if the user is in another page, it will be notified if there are new questions and eventually the page will be refreshed (always with a jquery call).

Are there better approaches or any possible performance penalties to this approach? Should I go with the separate Windows service?


回答1:


Your approach seems fine. Just make sure you are not using threads from the thread pool for executing the lengthy operation. Spawning a new thread manually could work just fine.



来源:https://stackoverflow.com/questions/5059334/async-fire-and-forget-operation-with-callback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!