Using ManualResetEvent to wait for multiple Image.ImageOpened events
Posted
by umlgorithm
on Stack Overflow
See other posts from Stack Overflow
or by umlgorithm
Published on 2010-04-09T05:07:51Z
Indexed on
2010/04/09
5:13 UTC
Read the original article
Hit count: 232
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?
© Stack Overflow or respective owner