Web 服务调用返回时加载动画冻结
我有一个 Silverlight 2 应用程序,其中有一条包含动画的“正在加载数据...”消息。 当 Web 服务返回数据并且数据正在加载到可观察集合中时,动画会冻结(在加载数据时这可能会持续几秒钟,给人一种可能出现问题的印象。
)数据绑定到视图中的项目控件。
我假设发生的情况是,当数据被添加到可观察集合中时,正在为数据绑定控件构建可视化树 - 这发生在 UI 线程上。
无论如何,我是否可以降低数据加载的优先级,以便 ui 线程上的动画可以继续 - 即使 UI 线程上正在完成大量数据工作?
谢谢 迈克尔
I have a Silverlight 2 application that has a "Loading Data..." message that contains an animation. When the web service returns the data and the data is loading in to an observable collection -- the animation freezes (this can be for for several seconds while the data is loading and give the impression that something moght be wrong.)
The observable collection that is databound to an items control in a view.
I assume what is happening is when the data is being added to the observable collection the visual tree is being built for the databound control - which happens on the UI thread.
Is there anyway for me to lower the priority of the data loading so the animation on the ui thread can continue -- even when there is a ton of data work being done on the UI thread?
thanks
Michael
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不知道你是否得到了答案,但我来了。
尝试使用 BackgroudWorker 将重型指令放在那里。
这是一个很好的例子: http://msdn.microsoft .com/en-us/library/system.componentmodel.backgroundworker.aspx
如果您有任何问题,请告诉我,或者如果您已经解决了此问题,请告诉我。
I don't know if you got the answer for this or not but here i go.
Try using a BackgroudWorker to put the heavy duty instructions in there.
Here is a very good example: http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx
Let me know if you have any issues, or let me know if you already solved this problem.
我一直在使用具有不确定状态的进度控件,然后将其放入项目控件顶部具有半透明背景的控件中。 我还没有看到它在进行 Web 服务调用时停止动画,返回对象被处理到 ViewModel 中,并且 ItemControl 正在渲染更新的视图模型。
我认为您可以以非常简单的方式自定义进度栏模板,并将“正在加载数据...”消息添加为 TextBlock。 我的进度控件上方也有一条正在加载...消息。
I have been using a Progress Control with Indeterminate state, and then put that in a control with a semi-transparent background over the top of the items control. I have not seen it stop animating while the web service call is made, the return objects are processed into a ViewModel and the ItemControl is rendering the updated view model.
I think you can customize the progress bar template in a pretty straightforward way as well as adding the Loading Data... message as a TextBlock. I have a Loading... message above the Progress control as well.
你说得对,回调发生在 UI 线程上。 要解决您的问题,您可以使其异步,以便它发生在后台线程上,然后构建一个新的可观察集合并在一次操作中替换现有的集合。
例如:
在我的开发中,我发现对于 DataGrid,我可以在 UI 线程上清除并添加新元素,而不会影响性能。 也许你可以重构你的 UI 代码?
You're right in saying that the callback happens on the UI thread. To solve your issue you can make it asynchronous so that it happens on a background thread and then build a new observable collection and replace the existing one in one operation.
For example:
In my development I found that for a DataGrid I could just clear and add the new elements on the UI thread without performance hit. Maybe you could refactor your UI code?
您的动画未运行,因为您的 JS 正在处理返回的数据。 (单线程浏览器。)
解决方案:您的 JS 加载 sw 需要定期屈服于浏览器,以使浏览器能够执行一些动画。
请参阅我的答案 为什么 jQuery Ajax 在 IE7 上如此慢? 了解有关如何操作的更多详细信息。
Your animation isn't running because your JS is dealing with the returned data. (Single threaded browser.)
Solution: your JS loading sw needs to yield to the browser periodically to enable the browser to do some animation.
See my SO answer Why is jQuery Ajax so slow on IE7? for more details on how to do it.