Context
A WPF UI has a user control that use COMs and DirectShow.NET. The WPF UI display the time used to transform a video frame.
I declare a float in the WPF UI. The float is passed by reference to my COM filter. The COM filter increments the float, each time a frame is transformed.
A timer is used to display the float to the screen every x mili seconds.
Also, keep in mind that multiple frames are modified per second, which means that the float is written multiple time per second. This is why I decided to not go with events and go with a reference float instead.
Problem
The same float is being read and written by two different threads, which cause a crash. The faster the read timer, the faster the crash occurs... for obvious reasons.
Question
Do I need to somehow lock the float in both threads ? If so, how ?
If possible, I want to keep the float a simple variable, not make it a property and not make it a class member. ( else it would require multiple changes in my COM, but I will do it if it's the only way. )
PS: I've read MultiThreading COMObject and UI Thread (C#) but couldn't understand it and not sure if it applies to my case.