如何将以下场景付诸实践? [英] How do I put following scenario into practice?

查看:88
本文介绍了如何将以下场景付诸实践?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SO。我正在开发一个应用程序,我需要进行长时间运行,在我测试它时,每个请求证明需要超过30k ms。它对第三方服务器执行一些API调用,并以Json和图像格式返回数据。

在搜索SO问题以及关于该问题的许多其他博客文章中,我发现只有两个选项。 />
1st。要使Action返回局部视图并在主视图上呈现它,显示一些花哨的加载GIF,直到动作进度完成。

2nd。必须编写API控制器并在那里进行后台工作。



这两种解决方案之间的最佳选择是什么?是否有任何其他技术我错过并处理情况更好?

谢谢



我的尝试:



我刚刚阅读有关Web API和相关内容的博客

SO. I am developing an application where I need to make long run Actions which proven to take more than 30k ms per request as I tested it. It does some API Calls to third party servers and return data in Json and Image formats.
Throughout searching SO questions and many other blog posts regarding the issue I have found out to have only two options.
1st. To make the Action return a partial view and render it on the main view showing some fancy loading gifs until the action progress is completed.
2nd. Have to write API Controllers and do the background work there.

What is the best choice between these two solutions and is there any other technique that I missed and deal with the situation better?
Thanks

What I have tried:

I am just reading blogs about Web APIs and related things

推荐答案

您可以尝试使用BackgroundWorker线程来执行长时间运行的进程并使用ReportProgress将进度发送回主线程。后台线程将在完成后发送回调。然后,您的主线程将主要负责运行花哨的加载GIF和GUI。
You could try using a BackgroundWorker thread to execute the long running process and use ReportProgress to send progress back to your main thread. The Background thread will send a callback when it's completed. Your main thread would then be primarily responsible for running "fancy loading gifs" and the GUI.


您实现的任何使用IIS的解决方案都将受到IIS关闭您的应用程序的支配如果它使用太多的内存等你可以将工作分配到Windows服务,也许使用MSMQ将请求发送到服务,服务执行所有实际工作,并提供可以通知前端的机制进步。
Any solution you implement that uses IIS is going to be at the mercy of IIS shutting down your app if it uses too much memory etc. You could farm the work off to a Windows Service, maybe using MSMQ to send the requests to the service, with the service doing all the actual work, and providing a mechanism where the front end can be informed of progress.


这篇关于如何将以下场景付诸实践?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆