开发者

Silverlight application not become Idle when using asynchronous AJAX

I'm currently working with a Silverlight 5 application that supports two-way communication between itself and JavaScript. The Silverlight application is responsible for rendering 3D content and the JavaScript is responsible for collecting and preparing the data for rendering.

The problem I am faced with, is that the Silverlight 5 DrawingSurface only re-draws after the DrawingSurface is invalidated and the application becomes Idle. Unfortunately, when downloading the data that I require from the server using asynchr开发者_如何学JAVAonous AJAX requests, the DrawingSurface does not re-draw until all of the data has been downloaded (despite invalidating the DrawingSurface after each piece of data has been downloaded).

I understand this, but what confuses me is that when I do exactly the same style of asynchronous download requests using the WebClient within Silverlight, the DrawingSurface successfully re-draws after most of the invalidation calls.

Originally, I thought this might have been due to some threading issue, but all calls (and callbacks) operate on the same thread. I've tried using both jQuery's AJAX API and writing my own XmlHttpRequest handler in JavaScript; but I get the same result both ways. I originally noticed that jQuery was returning the data in the same order that I was requesting it in (whereas Silverlight's WebClient was not), which is what lead me to creating my own XmlHttpRequest handler as I thought that re-ordering might have caused the script to remain active during asynchronous calls.

Has anyone had this issue before and/or does anyone have any suggestions for workarounds/fixes?


From what you explain, shouldn't invalidating the surface at the end of each draw calls (I little like a game's drawing loop) be an easy workaround? Your frame rate will grow, but in most scenarios, it won't be an issue (and it will make camera and resource management a lot easier).

Don't forget anyway that the rendering logic is executed on its own thread: You will have to lock appropriately your shared instances.

public void Draw(object sender, System.Windows.Controls.DrawEventArgs e)
{
   var device = e.GraphicsDevice;


   device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, new Color(0, 0, 0, 0f), 

   //Drawing logic.
   [...]

   e.InvalidateSurface();


}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜