I'm using Observal.subscribe to run a sub that changes a value of label with this code
Dim observ As IObservable(Of Long) = System.Reactive.Linq.Observable.Interval(TimeSpan.FromSeconds(10))
Dim source As New System.Threading.CancellationTokenSource()
Dim action As Action = (Sub() ChangeLed())
Dim resumeAction As Action = (Sub() ChangeLed())
observ.Subscribe(Sub(x)
Dim task As New Task(action)
task.Start()
task.ContinueWith(Sub(c) resumeAction())
End Sub, source.Token)
and the changeled() sub mentioned above is by example
private sub Changeled()
If PingHost("myhostIP") Then
label1.Content = "Connected"
Else
label1.Content = "Not Connected"
End If
end sub
I have an error says : "The calling thread cannot access this object because a different thread owns it." I know i have to use invoke By dispatcher here but i don't know where. ps:the pingHost is a function that returns true or false based on pinging a host