The calling thread cannot access this object because a different thread owns it, even when using the dispatcher

Shaked Dahan

I have a Paragraph object that I try to access from a different thread than it was created on, before posting my question here I searched for a solution online and I found the "Dispatcher" solution, which did not work for me, somehow.

Here's the code:

Run r = new Run((string)name + Environment.NewLine);
r.Foreground = Brushes.Green;
Dispatcher.Invoke(new Action(() => { currentlyOnlineParagraph.Inlines.Add(r); }), DispatcherPriority.ContextIdle);

I get this error:

InvalidOperationException was unhandled
An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll
Additional information: The calling thread cannot access this object because a different thread owns it.

screenshot

How can I address this?

Emmanuel DURIN

From the few lines of code I see,I would try to create all graphical objects on the graphical thread, including the Run object:

Dispatcher.Invoke(new Action(() => {   
   Run r = new Run((string)name + Environment.NewLine);
   r.Foreground = Brushes.Green;
   currentlyOnlineParagraph.Inlines.Add(r);   
}), DispatcherPriority.ContextIdle);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

The calling thread cannot access this object because a different thread owns it (with Dispatcher)

From

The calling thread cannot access this object because a different thread owns it

From Dev

the calling thread cannot access this object because a different thread owns it wpf

From Dev

The Calling thread cannot access this object because a different thread owns it,WPF

From Dev

WPF: The calling thread cannot access this object because a different thread owns it

From Dev

"The calling thread cannot access this object because a different thread owns it" error when updating UI control from different thread in WPF

From Dev

The thread cannot access an object because a different thread owns it when using wpf

From Dev

ReactiveUI WPF - The calling thread cannot access this object because a different thread owns it

From Dev

The calling thread cannot access this object because a different thread owns it - BackgroundWorker error

From Dev

Error:The calling thread cannot access this object because a different thread owns it. Storyboard simulation

From Dev

Getting error The calling thread cannot access this object because a different thread owns it wpf, How to use Dispatch.invovef

From Dev

c# - Changes in cefsharp 79.1.35 (from 75.1.143) creates: 'The calling thread cannot access this object because a different thread owns it.'

From Dev

Famous the calling thread cannot access this object because a different issue

From Dev

The calling thread cannot access this object even after adding Dispatcher.Invoke

From Dev

Updating image via Dispatcher still gives "different thread owns it" error

From Dev

Calling thread cannot access object when it's created from the same thread

From Dev

Different thread owns it in WPF

From Dev

Calling thread cannot access object due to separate thread ownership

From Dev

"calling thread cannot access this object" exception when working with live visual tree in multithreaded UI WPF app

From Dev

Error: Must create DependencySource on same Thread as the DependencyObject even by using Dispatcher

From Dev

delay() block its coroutine when using thread pool as the dispatcher?

From Dev

WPF error 'calling thread cannot access this object' trying to play sounds in c# class

From Dev

Why is IllegalMonitorStateException thrown despite the thread calling notifyAll owns the monitor?

From Dev

Is checking the Thread is "UI Thread" before Calling Dispatcher.Invoke redundant?

From Dev

Redshift - user "xyz" cannot be dropped because the user owns some object

From Dev

Getting an interface was marshaled for a different thread Exception with UI thread dispatcher call?

From Dev

sequential access to object with multiple thread using synchronized

From Java

Calling into a saved java object via JNI from a different thread

From Dev

InvalidOperationException, the calling thread should be STA because

Related Related

  1. 1

    The calling thread cannot access this object because a different thread owns it (with Dispatcher)

  2. 2

    The calling thread cannot access this object because a different thread owns it

  3. 3

    the calling thread cannot access this object because a different thread owns it wpf

  4. 4

    The Calling thread cannot access this object because a different thread owns it,WPF

  5. 5

    WPF: The calling thread cannot access this object because a different thread owns it

  6. 6

    "The calling thread cannot access this object because a different thread owns it" error when updating UI control from different thread in WPF

  7. 7

    The thread cannot access an object because a different thread owns it when using wpf

  8. 8

    ReactiveUI WPF - The calling thread cannot access this object because a different thread owns it

  9. 9

    The calling thread cannot access this object because a different thread owns it - BackgroundWorker error

  10. 10

    Error:The calling thread cannot access this object because a different thread owns it. Storyboard simulation

  11. 11

    Getting error The calling thread cannot access this object because a different thread owns it wpf, How to use Dispatch.invovef

  12. 12

    c# - Changes in cefsharp 79.1.35 (from 75.1.143) creates: 'The calling thread cannot access this object because a different thread owns it.'

  13. 13

    Famous the calling thread cannot access this object because a different issue

  14. 14

    The calling thread cannot access this object even after adding Dispatcher.Invoke

  15. 15

    Updating image via Dispatcher still gives "different thread owns it" error

  16. 16

    Calling thread cannot access object when it's created from the same thread

  17. 17

    Different thread owns it in WPF

  18. 18

    Calling thread cannot access object due to separate thread ownership

  19. 19

    "calling thread cannot access this object" exception when working with live visual tree in multithreaded UI WPF app

  20. 20

    Error: Must create DependencySource on same Thread as the DependencyObject even by using Dispatcher

  21. 21

    delay() block its coroutine when using thread pool as the dispatcher?

  22. 22

    WPF error 'calling thread cannot access this object' trying to play sounds in c# class

  23. 23

    Why is IllegalMonitorStateException thrown despite the thread calling notifyAll owns the monitor?

  24. 24

    Is checking the Thread is "UI Thread" before Calling Dispatcher.Invoke redundant?

  25. 25

    Redshift - user "xyz" cannot be dropped because the user owns some object

  26. 26

    Getting an interface was marshaled for a different thread Exception with UI thread dispatcher call?

  27. 27

    sequential access to object with multiple thread using synchronized

  28. 28

    Calling into a saved java object via JNI from a different thread

  29. 29

    InvalidOperationException, the calling thread should be STA because

HotTag

Archive