Background thread, async and GUI (dlangui)
Bagomot
bagomot at gmail.com
Fri Jul 8 13:32:33 UTC 2022
On Friday, 8 July 2022 at 08:04:45 UTC, Bagomot wrote:
> On Thursday, 7 July 2022 at 18:26:15 UTC, Ali Çehreli wrote:
>
> Summing up your help and GrimMaple, I understood how to make
> the file download progress bar beautifully. Thank you!
>
> I only have a question with how I can work with the GUI from
> other threads. For example, in my application I have a button
> (GUI) that starts a long running job. As I understand it, it
> should run it in a separate thread so as not to block the GUI.
>
> I did it through Thread, but now I realized that there are more
> convenient ways through Task.
>
> But I do not understand how I can manage the GUI from that
> separate task. For example, I start the task with the button
> and block the button press (without blocking the entire GUI),
> it does its job and unblocks the button.
>
> This is where help is needed. How is it fundamentally correct
> to do this in D, and how to do it in general with dlangui?
Let's even look at the example of downloading a file.
Here in my application I have a button and its click event. I can
set it to work on click. But I do not know how to do it so that
the GUI does not block for the duration of the work. I do as in
Ali's example, but the GUI is still blocked:
```d
auto btn = new Button("Run"d);
btn.click = delegate(Widget src) {
auto request = Request("dlang.org");
auto downloadTask = task!download(&request);
downloadTask.executeInNewThread;
return true;
};
```
How to do it right? Not only for downloading, but for any
background work in dlangui? Maybe someone knows?
More information about the Digitalmars-d-learn
mailing list