0

I would like to expose you my problem here. I'm trying to build a user interface in one of my application where the user can see multiple pictures (TImage objects) on the same form.

These pictures should be loaded from potentially large image files on the HDD. Obviously, sequentially loading all these TImages in the main thread takes time. It also freeze the main thread and thus avoid the user to interact with the software in the mean-time.

That's why i'm trying to load all these images in parallel tasks thanks to OTL while my user can still interact.

But i'm not sure which abstraction is best suited for it and how i'm supposed to use it. I'm aware of the issues related to accessing GUI components from other threads. From what i've read in documentations "ForEach" seams to be appropriate for my use case, although i'm not sure.

What are your thoughts on this use case?

Sorry for asking such a vague question here.

mathieu
  • 235
  • 2
  • 11
  • *'...which abstraction is best suited ... read in documentation "ForEach"...'*, what documentation do you refer to, what is the 'ForEach' you refer to? – Tom Brunberg Jan 05 '17 at 15:02
  • This one : http://otl.17slon.com/book/chap04.html#highlevel-foreach – mathieu Jan 05 '17 at 15:09
  • `Parallel.ForEach(sl).Execute(procedure (const value: string) begin Something(value); end);` would work, but I cannot say if the images are suitable for loading in threads. – LU RD Jan 05 '17 at 15:45
  • Actually i had something in mind that would load the images in memory to TBitmap objects within parallel tasks but would then assign those bitmaps to the corresponding TImage in the main thread since this operation seems not to be thread-safe – mathieu Jan 05 '17 at 16:03
  • 3
    Reading from disk in parallel won't help - it will be most efficient to read them sequentially. Just move the entire operation to a single background task and postback notifications when each image is done. – J... Jan 05 '17 at 17:43

0 Answers0