D
Dave Taylor
I'm writing a VB.NET app that controls some equipment. Some of the control
functions run on separate threads. For example the temperature control
object reads in the temperature value and adjusts the heater/cooler
accordingly and continuously loops on its own thread doing that. The temp.
control object has a property called SetPoint that can be set by another
thread. My question is, do I need to lock the writing of the value in the
property's set statement because the Execute routine (on its own thread)
will be reading the setpoint? and is it as simple as something like:
Public Class TempControl
Private _sp As Single
Public Property SetPoint() As Single
Get
Return _sp
End Get
Set (Value As Single)
SyncLock(_sp)
_sp = Value
End SyncLock
End Set
End Property
'Execute runs on its own thread, reading the _sp value and adjusting the
temperature output accordingly.
Private Sub Execute()
<do code here to control temperature>
End Sub
End Class
Thanks
Dave Taylor
functions run on separate threads. For example the temperature control
object reads in the temperature value and adjusts the heater/cooler
accordingly and continuously loops on its own thread doing that. The temp.
control object has a property called SetPoint that can be set by another
thread. My question is, do I need to lock the writing of the value in the
property's set statement because the Execute routine (on its own thread)
will be reading the setpoint? and is it as simple as something like:
Public Class TempControl
Private _sp As Single
Public Property SetPoint() As Single
Get
Return _sp
End Get
Set (Value As Single)
SyncLock(_sp)
_sp = Value
End SyncLock
End Set
End Property
'Execute runs on its own thread, reading the _sp value and adjusting the
temperature output accordingly.
Private Sub Execute()
<do code here to control temperature>
End Sub
End Class
Thanks
Dave Taylor