I'm using VB.NET to load images from a URL into a PictureBox control using LoadAsync. These are often very small images - sometimes 76x76 pixels. The delay in displaying them onscreen is extreme. I initially thought it was due to load time, but I added a log to the LoadComplete event and found that the image took 0.29 seconds to load but an additional 21 seconds (per my stopwatch) to display.
Public Sub ShowImage(ByRef image As PictureBox, imgUrl as String)
Log("Starting to load image")
AddHandler image.LoadCompleted, ImgFinish(image)
image.Image = Nothing
image.CancelAsync()
image.LoadAsync(imgUrl)
image.Visible = True
End Sub
Private Function ImgFinish(ByRef image As PictureBox)
Log("Image loading complete")
Return Nothing
End Function
And the log output:
(17:03:59.930) vb_Utilities.ShowImage[697] - V:Starting to load image
(17:04:00.220) vb_Utilities.ImgFinish[731] - Image loading complete
Then using a stopwatch I timed 21 additional seconds - to 17:25 - before the image appeared)
I also tried adding image.Refresh() to the function ImgFinish thinking that perhaps it just wasn't redrawing, but that didn't help.
What could be causing this delay? What can I check or try?