1
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會阻止當前的UI線程,所以ImageOpened/ImageFailed事件永遠不會被觸發。你能否建議我一個簡單的解決方法來等待多個ui事件?使用ManualResetEvent等待多個Image.ImageOpened事件