Link to home
Start Free TrialLog in
Avatar of ocsurf
ocsurf

asked on

Loading a lot photos, app does not respond

I have a function that selects photos,  resizes them and then adds them to a flowlayoutpanel.
I also have a progressbar to let the user know how long it is going to take.

It works great when only selecting a few photos. but i tested it with 80 1meg photos...the application turns white and the titlebar say Not responding. After the load/resize is done. The application returns.

How can i prevent this?
ASKER CERTIFIED SOLUTION
Avatar of Jeff Certain
Jeff Certain
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You also can use execute System.Windows.Forms.Application.DoEvents(); from time to time:
http://msdn2.microsoft.com/en-us/library/system.windows.forms.application.doevents.aspx

or use Thread.Sleep(miliseconds) to give it time to respond (DoEvents is better I think):
http://msdn2.microsoft.com/en-us/library/system.windows.forms.application.doevents.aspx
DoEvents won't let you take advantage of multiple cores or multiple CPUs, though.... this can only be done by having additional threads spun up.
Avatar of ocsurf
ocsurf

ASKER

perfect thanks!