Z
Z
Zulkund2016-09-27 15:16:07
C++ / C#
Zulkund, 2016-09-27 15:16:07

How to avoid InvalidOperationException in C#?

Good afternoon! Faced such a problem. In the main thread, I open a child thread in which I work with the form object (progressBar). An exception is thrown:
Additional information: Illegal multi-thread operation: An attempt was made to access control 'pB1' from a thread other than the thread it was created on. How can this be avoided? Transferring flow work from a form is not an option. Thanks in advance!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
Peter, 2016-09-27
@Zulkund

Work with form elements is possible only from the thread in which they are created.
If you want to update the progressBar, pass the value from your helper thread to the main thread and it will update the progressBar already

D
Dmitry Gavrilenko, 2016-09-27
@Maddox

Dispatcher should solve the problem

A
Anton Fedoryan, 2016-09-27
@AnnTHony

Through the mechanism of events probably too can turn out.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question