I'm currently working on a .NET Desktop application that will be loading potentially large images from disk. Using Image.FromFile
works fine, but because these images are potentially quite large I'd like to support some form of progress reporting and cancellation (cancellation being more important to me than progress reporting).
The image needs to be loaded into memory and won't be immediately shown in a UI control, so using something like the PictureBox.LoadAsync/CancelAsync
doesn't seem like it's an option (though if there's a way to use a PictureBox
to load an image without having it actually present on a parent form/control then I'm open to that).
I'm aware that I can pretty easily read the bytes of the image file from disk with good progress/cancellation support, but the act of getting into an Image
(via Image.FromStream
in that case) is still a fairly long-running process for larger images.
I'm also aware that I could achieve cancellation via Thread.Abort()
, but I'm trying to avoid that approach if possible.
How can I accomplish in .NET?