| Visual Basic (Declaration) | |
|---|---|
Public Event StateChanged As EventHandler | |
| Visual Basic (Usage) | Copy Code |
|---|---|
Dim instance As TcpBase Dim handler As EventHandler AddHandler instance.StateChanged, handler | |
| C# | |
|---|---|
public event EventHandler StateChanged | |
| Managed Extensions for C++ | |
|---|---|
public: __event EventHandler* StateChanged | |
| C++/CLI | |
|---|---|
public: event EventHandler^ StateChanged | |
This example demonstrates using the component State to update the UI.
| C# | Copy Code |
|---|---|
private void myComponent_StateChanged(object sender, EventArgs e) { //Always raised when connection is established or closed (State property changes) switch (myComponent.State) { case Dart.Common.ConnectionState.Connected: case Dart.Common.ConnectionState.ConnectedAndSecure: //Update interface to indicate connection textDisplay.ReadOnly = false; textDisplay.BackColor = Color.WhiteSmoke; Text = (myComponent.State == Dart.Common.ConnectionState.Connected) ? APP_NAME + " [Connected to " + myComponent.RemoteEndPoint.Address.ToString() + ":" + myComponent.RemoteEndPoint.Port.ToString() + "]" : APP_NAME + " [Securely Connected to " + myComponent.RemoteEndPoint.Address.ToString() + ":" + myComponent.RemoteEndPoint.Port.ToString() + "]"; break; case Dart.Common.ConnectionState.Closed: //Update interface to indicate no connection textDisplay.ReadOnly = true; textDisplay.BackColor = Color.Silver; this.Text = APP_NAME + " [Not Connected]"; break; } } | |
| C# | Copy Code |
|---|---|
Private Sub myComponent_StateChanged(ByVal sender As Object, ByVal e As EventArgs) Handles myComponent.StateChanged 'Always raised when Connection is established or closed (State property changes) Select Case myComponent.State Case Dart.Common.ConnectionState.Connected, Dart.Common.ConnectionState.ConnectedAndSecure 'Update interface to indicate connection textDisplay.ReadOnly = False textDisplay.BackColor = Color.WhiteSmoke If (myComponent.State = Dart.Common.ConnectionState.Connected) Then Text = APP_NAME & " [Connected to " & myComponent.RemoteEndPoint.Address.ToString() _ & ":" & myComponent.RemoteEndPoint.Port.ToString() & "]" Else Text = APP_NAME & " [Securely Connected to " & myComponent.RemoteEndPoint.Address.ToString() _ & ":" & myComponent.RemoteEndPoint.Port.ToString() & "]" End If Case Dart.Common.ConnectionState.Closed 'Update interface to indicate no connection textDisplay.ReadOnly = True textDisplay.BackColor = Color.Silver Me.Text = APP_NAME & " [Not Connected]" End Select End Sub | |
This method is raised on the UI thread if the SynchronizingObject is set. Otherwise this event is raised on a worker thread.
Target Platforms: Microsoft .NET Framework 2.0