1

I have an application that has a main UI and two modeless windows that run on the their own separate thread. When passing an object from thread to thread I just make a copy of of the object running on the main thread on the secondary thread. When I want to update the object itself and have that changed perpetuated down through the code and to the secondary thread how do I make this happen??? The secondary thread always keeps a copy of the old object and never updates unless the thread is killed or stopped and then spawned again.

jharr100
  • 1,449
  • 24
  • 51
  • 9
    Why do you make a copy of the object? It's much simpler to reference the same object from multiple threads and use concurrency semantics to ensure any changes to the object are atomic. – Eric J. Oct 18 '11 at 19:14

1 Answers1

0

There are a number of ways to tackle this. One would be a thread-safe shared instance of a repository for the object. When one thread updates it, the others would get an updated copy. You could use WCF to make this easy. See this article on WCF and concurrency for some ideas. This is an implementation of @Eric J's comment to your question.

Another would be to coordinate the threads via events. When one thread updates the object, an event is sent to the others. If the object doesn't change that often, it may be enough.

This question talks about a third possibility: BackgroundWorker.

Community
  • 1
  • 1
neontapir
  • 4,698
  • 3
  • 37
  • 52
  • well im using wpf and im using dispatcher for majority of the calls...this object should update but its not – jharr100 Oct 18 '11 at 20:06
  • I submitted a edit to include that information in the body of the question and tagged it appropriately. I don't have enough WPF experience to offer any further aide. Good luck! – neontapir Oct 20 '11 at 20:00