0

During update a value in a CMFCPropertyGridProperty from another thread, my application crashes. I assume it's a timing issue because setting the value in same thread via another function works. The question is how to solve this?

My first idea was to copy the values and set them later with a timer but this sounds a bit clumsy...

What is the best practice to set property from another thread?

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
boiler
  • 140
  • 10
  • 1
    *"how to solve this"* - By only modifying a control from the thread that owns the control (i.e. the thread that called `CreateWindow`). – IInspectable Apr 17 '20 at 10:21
  • Agreed but is there any mechanism to do it in a more prettier way? Example: If i want to draw new content to a window by myself I call InvalidateRect, which will lead into a WM_PAINT event... – boiler Apr 17 '20 at 11:15
  • 1
    It's not clear what *"prettier"* means to you. The point is, UI's are single-threaded, practically across all platforms. If you want a solution, you're going to have to modify your UI from the thread that owns the UI. That doesn't imply that all your processing needs to (or should) run on your UI's thread. Without any hint as to what you are trying to accomplish, there's very little we can do to help. – IInspectable Apr 17 '20 at 12:25
  • 1
    Don't set the value from threads; use `SendMessage` function; captures the message in the other side, and modifies the value – Landstalker Apr 17 '20 at 14:39
  • Thanks, I think I will use SendMessage approach. – boiler Apr 20 '20 at 05:58

0 Answers0