Private Sub button1_Click(sender As Object, e As EventArgs)
' Any number of clients can attach to the event from the Background service.'
RemoveHander BackgroundService.Message, AddressOf BackgroundService_Message
AddHandler BackgroundService.Message, AddressOf BackgroundService_Message
_subscribed = Not _subscribed
Me.button1.Text = If (_subscribed, "Unsubscribe", "Subscribe")
Private _subscribed as Boolean
' The event handler is called by the Background service thread, so the thread'
' does not have any knowledge of the session, but "this" refers to this specific'
' object, which allows Wisej to restore the context while executing the code below.'
Private Sub BackgroundService_Message(sender As Object, e As BackgroundServiceEventArgs)
' Application.Update() can optionally call a code block in context before updating the UI.'
Application.Update(Me, Sub()
Me.label1.Text = e.Message