Dictionary<Image, ManualResetEvent> waitHandleMap = new Dictionary<Image, ManualResetEvent>();
List<Image> images = GetImagesWhichAreAlreadyInVisualTree();
foreach (var image in images)
{
image.Source = new BitmapImage(new Uri("some_valid_image_url"));
waitHandleMap.Add(image, new ManualResetEvent(false));
image.ImageOpened += delegate { waitHandleMap[image].Set(); };
image.ImageFailed += delegate { waitHandleMap[image].Set(); };
}
WaitHandle.WaitAll(waitHandleMap.Values.ToArray());
WaitHandle.WaitAll blocks the current UI thread, so ImageOpened/ImageFailed events would never get fired. Could you suggest me an easy workaround to wait for the multiple ui events?