max

max

  • NA
  • 1
  • 10.2k

Silverlight: Threading Problem

Jan 4 2011 1:22 PM


Hi,

I am new to silverlight and I would like to use silverlight for a simple project because of the nice, simple animations.
What I try to do now is to add several images through Drag&Drop to my silverlight application. When I drag for example 10 images to my application I would like it to visualize a preview of the images. I would like to use some kind of fade in effect for the images (the effect lasts about 2s.
So what I tried is the following:
  1. On the drag&drop callback I add the FileInfo to a list of unprocessed images (to avoid processing in the UI thread)
  2. Use a worker thread to load an image from disk, resize it to a size of 150x150pixels and add it to a list of processed images
  3. In the rendering callback I check the list and if there is a processed image I start visualizing it using the animation. The worker thread for image loading in the meantime continues with the next image


My problem now is that the animations are absolutely not smooth. I think the reason is because the worker thread uses a lot of cpu for resizing the next image while a finished image is getting visualized.

However, there seems to be no possibility to reduce the priority of the worker thread to improve things. What I could do is wait until an image is fully visualized before I continue with the next (or wait until all images are finished and then visualize them at once). However this way the visualization would slow down the image processing significantly. After loading each image I would have to wait for 2s before continuing working on the next image. In a multicore environment this would be nonsense,...

Does anyone have an idea how to solve this?

Markus