Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 11.0.1 (中文) » UltraLite - .NET 编程 » UltraLite .NET 2.0 API 参考 » ULConnection 类

 

StateChange 事件

当此连接更改状态时发生。

语法
Visual Basic
Public Overrides Event StateChange As StateChangeEventHandler
C#
public event override StateChangeEventHandler StateChange;
注释

要处理状态更改消息,必须创建一个 System.Data.StateChangeEventHandler 委派,并将其附加到此事件。

示例

以下代码定义了一个状态更改事件处理程序。

' Visual Basic
Private Sub MyStateHandler( _
      obj As Object, args As StateChangeEventArgs _
    )
  System.Console.WriteLine( _
      "StateHandler: " + args.OriginalState + " to " _
      + args.CurrentState _
    )
End Sub

// C#
private void MyStateHandler(
      object obj, StateChangeEventArgs args
    )
{
  System.Console.WriteLine(
      "StateHandler: " + args.OriginalState + " to "
      + args.CurrentState
    );
}

以下代码会将 MyStateHandler 添加至名为 conn 的连接。

' Visual Basic
AddHandler conn.StateChange, AddressOf MyStateHandler

// C#
conn.StateChange += new StateChangeEventHandler(MyStateHandler);
事件数据
  • CurrentState   获取连接的新状态。触发事件时,连接对象将已处于新状态。

  • OriginalState   获取连接的原始状态。

另请参见