通过异步任务的单独工作线程提高 UI 响应能力
我的 silverlight 应用程序从 asmx web 服务异步获取两组文件(假设 A 组和 B 组,A 组有几个文件,B 组有大量文件)。在接收到一组中的每个文件时,应该对其进行解析并且需要更新一些数据结构。 一旦接收到整个集合 A,就会向 Web 服务发出异步请求以获取集合 B。
接收到集合 A 后,应用程序就可以使用了。但由于仍在从 B 组接收文件,因此 UI 的响应速度不是很好。有什么方法可以提高在后台获取和处理文件时的响应能力。 Web 服务处理程序的 async_task_completed 是否在不同线程上工作。拥有一个 BackgroundWorker
线程有意义吗?
编辑:只是为了澄清,一组(数百个文件)的异步请求是一起发出的。
My silverlight application fetches two sets of files from an asmx webservice (say set A and set B, set A has a few files and set B has a large number of files) asynchronously. On receiving each file in a set, it should be parsed and some data structures need to be updated.
As soon as the whole set A is received, an async request is made to the webservice to fetch set B.
When set A is received, the application is ready to use. But since the files are still being received from set B, the UI is not very responsive. Is there any way to improve the responsiveness while files are being fetched and processed in background. Does async_task_completed of webservice handlers work on different threads. Does it make sense to have a BackgroundWorker
thread?
EDIT: Just to clarify, async request for a set (hundreds of files) are issued together.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
消除等式中的猜测工作。只需将此行暂时放入 Web 服务调用的完成代码中即可。
如果您看到“True”,则表示您位于 UI 线程上,因此您(至少)需要离开它来进行处理。正如您建议的一种简单方法是使用
BackgroundWorker
。如果您看到“False”,那么您已经处于后台线程中,因此如果来自其他来源,您的性能问题。
Take the guess work out of the equation. Just drop this line temporarily into the completion code of your web service calls.
If you see "True" you are on the UI thread and so you (at least) need to get off it to do your processing. As you suggest an easy way to do that is use a
BackgroundWorker
.If you see "False" you are on a background thread already so your performance issues if of another source.