Accessing object created by another thread

Asked

Viewed 43 times

0

I am creating an application in C#. The graphical interface elements are created by main-thread, and put a second thread to perform a process that is too long.

The problem is that I am trying to access an element of the graphical interface with this second thread and I’m getting an exception like "invalid operation".

The interface object I’m trying to access is a progress bar:

ProgressBar.IsInderterminate = true; // linha da exceção

How can I access this object through my second thread?

  • There’s no way to answer that by looking at a line of code. Even this property does not document this exception, so the problem occurs elsewhere, even if it ends up there. No code, no details no help.

  • 1

    Actually, there is @bigown He is trying to access a control created on thread main by another thread and this is not possible (not naturally).

  • But the question is duplicated from this other (Modify visual element by another thread)

  • @jbueno I find it even possible to infer about what it is, but it may not be what it looks like because it has almost nothing describing the problem. We don’t even know if it uses STA, even if it’s likely.

  • I did it. Thank you. There’s no more detail. This exception is the only message from the debugger. I have to make the statement in a special way. STA issues throw another type of exception.

  • @jbueno , the duplication of the question is almost inevitable for a beginner, because the question of the indicated link is so that I cannot identify that it is the same problem, although the answer serves.

  • @Paulo I know. Not to mention that the search system of the site is horrible. Duplicates are not a bad idea, it is only important to keep them linked.

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.