异步火忘了回调操作 [英] Async fire and forget operation with callback
问题描述
我有疑问的地方,可以通过e-mail还贴了一个论坛区的MVC3应用程序。
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.
我想首先创建一个单独的Windows服务的一些计划过程中,会做所有单独的电子邮件每隔几秒钟处理。
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:
- 的用户打开了MVC应用程序 页论坛区
- 异步过程被启动,将尽一切慢的东西,这个过程可以通过一个jQuery / JavaScript调用时,页面加载控制器启动。
- 控制器会叫的电子邮件分析服务,并会立即返回(发射后不管)。
- 每个后续调用,还从其他用户的启动电子邮件处理将工作过程中忽略的同一个控制器。
- 当该过程完成后,也如果用户是在另一页时,将是否有新的问题,并在最终的页将被刷新(总是与一个jquery呼叫)通知。
是否有更好的方法或任何可能的性能损失,以这种方式?我应该用单独的Windows服务去了?
Are there better approaches or any possible performance penalties to this approach? Should I go with the separate Windows service?
推荐答案
您的方法似乎罚款。只要确保你没有使用线程池中的线程来执行冗长的操作。手动产卵一个新的线程可以工作得很好。
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.
这篇关于异步火忘了回调操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!