DFL background tasks

Scroph via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jun 7 06:34:56 PDT 2015


On Sunday, 7 June 2015 at 12:30:40 UTC, Adam D. Ruppe wrote:
> For the Invoke call, you should be able to just ignore most the 
> arguments and write something like
>
> listview.invoke( delegate Object(Object[]) {
>     listview.Add(whatever);
>     return null;
> });
>
> and it should work.

Hello Adam, thanks for the fast reply. I tried your code and it 
did work, however it still froze the UI while it was retrieving 
the data.

I'm not sure if I'm using it correctly, I put the invoke call 
inside a Button.click callback. Here's a stripped down version of 
the code : 
https://gist.github.com/Scroph/0f3191fcd8b99db04d4b#file-dfl-d-L14-L17

A few days ago I read abot the XY problem 
(http://xyproblem.info/), so maybe I'm not asking the right 
questions. Here's what I'm actually trying to do : after clicking 
the button, I would like for the UI to remain responsive while :

a) A worker thread retrieves the needed information and places it 
in the ListView or,
b) A worker thread (or an asynchronous task maybe ?) retrieves 
the information and messages the UI with the data when it 
finishes running.

The latter seems to be more idiomatic because it separates the 
"data retrieval" bit from the "UI modification" bit, but I'm not 
sure if DFL does things this way. I tried spawn()ing a worker 
thread from the Button.click callback and receiveOnly(VideoInfo) 
from it, but this too ended up freezing the UI.

Thanks in advance.


More information about the Digitalmars-d-learn mailing list