V
V
Vladislav2020-09-01 13:31:09
.NET
Vladislav, 2020-09-01 13:31:09

How to make the UI "wait" for an operation to complete?

There is a desktop utility. It reads a large table from a file.
How to make the UI not block while the file is being processed?
Advise sensible guide on streams.
They didn’t ban me on Google, but I can’t find it myself, since I’m new to dotNet. Too complex material.
An async method is not needed.
It is only necessary that the status "Processing a file ..." be in the window while the file is being loaded, but the window itself should be active.

UPD: The problem with streams is that there can be several files. And each new file is added to the MyTable object via the add_file method. That is, we have some kind of state that needs to be stored between reading files.

UPD2: In another way, how to change the object that was created in the UI thread in a new thread and not block the UI thread?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
twobomb, 2020-09-01
@twobomb

(new Thread(() => {
                Invoke(new Action(() =>
                {
                    mylabel.Text = "Обработка файла...";
                }));

                //Тут обработка файла
                Invoke(new Action(() =>
                {
                    mylabel.Text = "Обработка файла завершена!";
                }));

            })).Start();

B
BasiC2k, 2020-09-02
@BasiC2k

Read the rsdsn article about streams. I recommend to everyone. Flows are a topic that you need to dive into completely.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question