2

I have a worker thread in a class that is owned by a ChildView. (I intend to move this to the Doc eventually.) When the worker thread completes a task I want all the views to be updated. How can I make a call to tell the Doc to issue an UpdateAllViews()? Or is there a better approach?

Thank you.


Added by OP: I am looking for a simple solution. The App is running on a single user, single CPU computer and does not need network (or Internet) access. There is nothing to cause a deadlock.

I think I would like to have the worker thread post (or send) a message to cause the views to update.

Everything I read about threading seems way more complicated than what I need - and, yes, I understand that all those precautions are necessary for applications that are running in multiprocessor, multiuser, client-server systems, etc. But none of those apply in my situation.

I am just stuck at getting the right combination of getting the window handle, posting the message and responding to the message in the right functions and classes to compile and function at all.

Harvey
  • 2,062
  • 2
  • 21
  • 38
  • @Harvey: Multithreading is not restricted to multiprocessor/core, multiuser or client-server systems and you CAN run into deadlocks even for the simplest situations as soon as you have more than one thread and when you deal with inter-thread communication. But your idea to post a message to the main thread for GUI update is good (use PostMessage in the worker thread, NOT SendMessage!). Here is another question with useful answers, very closely related to yours: http://stackoverflow.com/questions/391125/how-to-change-pane-text-of-status-bar-from-a-thread-in-mfc – Slauma Apr 08 '10 at 00:11

1 Answers1

2

UpdateAllViews is not thread-safe, so you need to marshal the call to the main thread. I suggest you to signal a manual-reset event to mark your thread's completion and check the event's status in a WM_TIMER handler.

suggested reading:

Sheng Jiang 蒋晟
  • 15,125
  • 2
  • 28
  • 46
  • @Sheng, Thank you. I now have the message posting working. I will accept your answer to close the question, even though I didn't do it that way. Thanks again. – Harvey Apr 04 '10 at 03:31