K
K
kosyak_472021-06-05 10:57:22
C++ / C#
kosyak_47, 2021-06-05 10:57:22

Why can't I assign values ​​and call the ProgressBar and Label methods on a separate thread?

Good afternoon.

There is a method (uploading photos via URL links) that I want to execute in a separate thread, because my program freezes every time I access a link to the site. I added a ProgressBar element (an operation progress indicator) to the form, and above it a Label , which displays the current image being loaded and how much is left to download.

The problem is that after entering the flow, execution stops at adding the step of the previously created ProgressBar

...
this.progressBar_LoadInfo.PerformStep();
...


C# tells me:
System.InvalidOperationException: "Invalid multi-thread operation: Attempt to access control 'progressBar_LoadInfo' from a different thread than it was created on."

Similar error on Label

...
this.label_progressBarLoadInfo.Text = "Загрузка файла " + splitUrl[splitUrl.Length - 1] + "      " + (i + 1).ToString() + " из " + data.Count().ToString();
...


Tried with this and without this .

How do I change the loading indicator and the status bar out of the thread when they should change in it? I'm sure I'm doing something wrong

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Korotenko, 2021-06-05
@kosyak_47

Follow this article and everything will work https://docs.microsoft.com/en-us/dotnet/desktop/wi...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question