Monday, December 31, 2012

Silverlight Application Almost Freezes When Loading Images Using WebClient

Silverlight Application Almost Freezes When Loading Images Using WebClient

I have this weird issue.

The code I have on my main thread:

WebClient client = new WebClient(); client.OpenReadCompleted += new OpenReadCompletedEventHandler((ss, ee) => {     Dispatcher.BeginInvoke(() =>     {         try         {             BitmapImage bi = new BitmapImage();             bi.SetSource(ee.Result);             WriteableBitmap wb = new WriteableBitmap(bi);             _okAction.Invoke(linkTexBox.Text, wb);              theProgressBarDialog.Close();         }         catch (Exception)         {             theProgressBarDialog.Close();              string msg = "Cannot fetch the image.  Please make sure the image URL is correct";             MessageBox.Show(msg);         }     }); }); client.OpenReadAsync(new Uri("Image URL without cross domain problem")); theProgressBarDialog.Show(); 

The image is loaded successfully, and got rendered on my canvas.

The weird behavior is sometimes, my whole Silverlight application seems freezing, the app does not respond to any user action EXCEPT the right-click, which pops up the default Silverlight context menu.

The buttons are disabled forcefully.

When debugging, no exception is thrown.

Answers & Comments...




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog