' Visual Basic
Imports iAnywhere.Data.UltraLite
Public Class MainWindow
Inherits System.Windows.Forms.Form
Implements ULActiveSyncListener
Private conn As ULConnection
Public Sub New(ByVal args() As String)
MyBase.New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent call.
ULConnection.DatabaseManager.SetActiveSyncListener( _
"myCompany.myapp", Me _
)
' Create Connection
...
End Sub
Protected Overrides Sub OnClosing( _
ByVal e As System.ComponentModel.CancelEventArgs _
)
ULConnection.DatabaseManager.SetActiveSyncListener( _
Nothing, Nothing _
)
MyBase.OnClosing(e)
End Sub
Public Sub ActiveSyncInvoked( _
ByVal launchedByProvider As Boolean _
) Implements ULActiveSyncListener.ActiveSyncInvoked
Me.Invoke(New EventHandler(AddressOf Me.ActiveSyncAction))
End Sub
Public Sub ActiveSyncAction( _
ByVal sender As Object, ByVal e As EventArgs _
)
' Perform active sync.
conn.Synchronize()
ULConnection.DatabaseManager.SignalSyncIsComplete()
End Sub
End Class
以下代码是 C# 语言等效代码:
// C#
using iAnywhere.Data.UltraLite;
public class Form1 : System.Windows.Forms.Form, ULActiveSyncListener
{
private System.Windows.Forms.MainMenu mainMenu1;
private ULConnection conn;
public Form1()
{
//
// Required for Windows Form Designer support.
// InitializeComponent();
//
// TODO: Add any constructor code after the
// InitializeComponent call.
//
ULConnection.DatabaseManager.SetActiveSyncListener( _
"myCompany.myapp", this _
);
// Create connection
...
}
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
protected override void OnClosing( _
System.ComponentModel.CancelEventArgs e )
{
ULConnection.DatabaseManager.SetActiveSyncListener(null, null);
base.OnClosing(e);
}
public void ActiveSyncInvoked(bool launchedByProvider)
{
this.Invoke( new EventHandler( ActiveSyncHandler ) );
}
internal void ActiveSyncHandler(object sender, EventArgs e)
{
conn.Synchronize();
ULConnection.DatabaseManager.SignalSyncIsComplete();
}
}