Background thread, async and GUI (dlangui)

Ali Çehreli acehreli at yahoo.com
Fri Jul 8 21:47:32 UTC 2022


On 7/8/22 06:32, Bagomot wrote:

 > I do as in Ali's example, but
 > the GUI is still blocked:

I don't know exactly why but something looks suspicious.

 > ```d
 > auto btn = new Button("Run"d);
 > btn.click = delegate(Widget src) {
 >      auto request = Request("dlang.org");

That is a local variable which will die after the return statement...

 >      auto downloadTask = task!download(&request);

... and that pointer will be invalid, still pointing on function call stack.

At least, I would move the 'auto request' line up, next to 'btn' so that 
it lives long and that you can get the 'result' later on.

But then, you need access to 'task' as well so that you can ensure it 
has finished with downloadTask.yieldForce().

 >      downloadTask.executeInNewThread;
 >      return true;
 > };

Aside: What does the return value 'true' mean?

I am not sure whether my explicit way of starting a thread (albeit with 
std.parallelism) is the right way here. As you've been suspecting, 
dlangui may provide async execution. (?)

Ali



More information about the Digitalmars-d-learn mailing list