I am nearly ashamed to ask this, but... EDIT: I edited the question to show the code I have come up with. It does not work... No "test" caption becomes visible on the main form.
Private _dispatcher As Dispatcher
Delegate Sub SetLabelText(caption As String)
Private _setLabelText As SetLabelText
Public Sub New()
_setLabelText = New SetLabelText(AddressOf SetConnectionStatus)
_dispatcher = Dispatcher.CurrentDispatcher
',,,
End Sub
Public Sub Connect
Try
_dispatcher.BeginInvoke(DispatcherPriority.Normal, _setLabelText, "test")
ConnectionStatus = "Connecting to server..."
_client = WCFClient.GetClient
Response = _client.GetInfo(Request)
ConnectionStatus = "Connected to server"
Catch ex As System.TimeoutException
ConnectionStatus="Timeout"
Catch ex As System.ServiceModel.EndpointNotFoundException
ConnectionStatus="Server down"
End Try
End Sub
Private Sub SetConnectionStatus(statusMessage As String)
ConnectionStatus = statusMessage
End Sub
Private _connectionStatus As String
Public Property ConnectionStatus() As String
Get
Return _connectionStatus
End Get
Set(ByVal value As String)
_connectionStatus = value
OnPropertyChanged("ConnectionStatus")
End Set
End Property
Private Sub OnPropertyChanged(propertyName As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End Sub
Public Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged
This bit of code lives in my ViewModel for a WPF form, change notification is implemented through INotifyPropertyChanged. The ConnectionStatus property is bound to the Content of a Label on the form.
The 'Connecting to server..' message is never shown, only one of the three resulting statusmessages. Obviously I have to move some task to an other thread. What is the easiest way to do it?