c# - How do I detect a BitmapImage failing to load? -
i have following code load image url. if url doesn't exist, placeholder should loaded instead.
public bitmapimage image { { if (m_image == null) { try { bitmapimage image = new bitmapimage(); image.begininit(); image.urisource = new uri(m_photopath); image.decodepixelheight = s_imagepixelheight; image.endinit(); m_image = image; } catch (filenotfoundexception) { bitmapimage image = new bitmapimage(); image.begininit(); image.urisource = new uri(c_placeholderimagepath); image.decodepixelheight = s_imagepixelheight; image.decodepixelwidth = s_imagepixelwidth; image.endinit(); m_image = image; } } return m_image; } }
i'm getting weirdest error - when m_photopath
url causes 404 in browser, no exception thrown. i've tried checking if file exists using httpwebrequest
, everytime call [httpwebrequest instance].getresponse()
, there's really, long timeout (possibly infinite - haven't waited around find out). httpwebrequest
isn't option. ideas?
if image fails download, bitmapimage's downloadfailed event fires. no exception thrown. can wire event anytime, though pragmatic before calling endinit!
this couldn't handled exception, since give on downloading image @ arbitrary point in future - there's put try/catch block.
Comments
Post a Comment