There is a BitmapImage and it has a problem. You can't just create it. You can only start its initialization, after which it will generate events, such as DownloadCompleted or DownloadFailed . And I need to make sure that the method in which it is initialized does not return anything until the initialization has passed. But how? Do not set the while .

    1 answer 1

    For example:

     var bi = new BitmapImage(); bi.BeginInit(); bi.CacheOption = BitmapCacheOption.OnLoad; bi.UriSource = ...; bi.EndInit(); // если передаёте в другой поток, ещё нужно bi.Freeze(); 

    Since loading may be slow, I would recommend bringing to the background thread via Task.Run :

     BitmapImage image = await Task.Run(() => { var bi = new BitmapImage(); // ... return bi; });