How to save your C # Windows Form Responsive while it rolls over?

I have such a massive nested loop script that calls the database and makes HTTP requests to the Basecamp API. At first it was a web application, but it took a long time to start the application, so the user (invoicing department) often left early or complained, because he would take so much time without feedback and could not cancel it. I wanted to make it more responsive and give it a Cancel button, as well as a real-time log, and I would like to make it more controlled. I put it in forms so that they could control all its instances and have a cancel button and a real-time log.

However, when I connected everything with the form buttons, a multi-line text box to replace the log of answers and errors, I can not get anything to work! I added checks in the loop to break out if I click Cancel. However, I cannot even cancel the cancellation, and multi-line TextBoxwill not be updated when I .Text.Insert and then .Update (). The whole application just sits there and rotates ... How do I get it to respond, accept button clicks during a loop, and live update multi-line TextBox?

NOTE: the thing compiles fine, and I can go through it, and it is written to the log file just fine, so I can say that it works after my form freezes, looking at this log file.

Here is the code I'm trying to update multi-line TextBoxusing

TimeSyncLog.Text.Insert(TimeSyncLog.Text.Length, "(((" + clientCode + ")))\n");

:

if(CancelPressed)
{
    TimeSyncLog.Text.Insert(TimeSyncLog.Text.Length,"\n\nSYNC STOPPED BY USER.");
    break;
}

"" , boolean, " "...

+3
2

-. BackgroundWorker . .

.

+14

. - , .

BackgroundWorker - , , , . , , GUI-, , "". , , , - . , .

0

Source: https://habr.com/ru/post/1722212/


All Articles