Public Class InvokeHelper(Of ValueType As System.Windows.Forms.Control)
Private Delegate Sub DeleSetPropertyValue(ByVal obj As ValueType, ByVal pPropertyName As String, ByVal pPropertyValue As Object)
Private Delegate Function DeleGetPropertyValue(ByVal obj As ValueType, ByVal pPropertyName As String) As Object
Private Sub SetPropertyValue(ByVal obj As ValueType, ByVal pPropertyName As String, ByVal pPropertyValue As Object)
Dim PropertyInfo As System.Reflection.PropertyInfo = obj.GetType.GetProperty(pPropertyName)
PropertyInfo.SetValue(obj, pPropertyValue, Nothing)
End Sub
Private Function GetPropertyValue(ByVal obj As ValueType, ByVal pPropertyName As String) As Object
Dim PropertyInfo As System.Reflection.PropertyInfo = obj.GetType.GetProperty(pPropertyName)
Return PropertyInfo.GetValue(obj, Nothing)
End Function
Public Property ThreadSafelyProperty(ByVal obj As ValueType, ByVal pPropertyName As String) As Object
Get
If obj.InvokeRequired = True Then
Dim pDele As New DeleGetPropertyValue(AddressOf GetPropertyValue)
Return obj.Invoke(pDele, pPropertyName)
Else
Return GetPropertyValue(obj, pPropertyName)
End If
End Get
Set(ByVal value As Object)
If obj.InvokeRequired = True Then
Dim pDele As New DeleSetPropertyValue(AddressOf SetPropertyValue)
obj.Invoke(pDele, obj, pPropertyName, value)
Else
SetPropertyValue(obj, pPropertyName, value)
End If
End Set
End Property
End Class
窗体控件线程安全类
最新推荐文章于 2024-07-04 11:14:48 发布