Public Class MainWindow Inherits System.Windows.Forms.Form Implements ULServerSyncListener
Private conn As ULConnection
Public Sub New(ByVal args() As String) MyBase.New()
' [Windows 窗体设计器] 需要此调用。InitializeComponent()
'Add any initialization after the InitializeComponent() call ULConnection.DatabaseManager.SetServerSyncListener( _ "myCompany.mymsg",
"myCompany.myapp", Me _ ) 'Create Connection ...End Sub
Protected Overrides Sub OnClosing( _ ByVal e As System.ComponentModel.CancelEventArgs _ ) ULConnection.DatabaseManager.SetServerSyncListener(
_ Nothing, Nothing, Nothing _ ) MyBase.OnClosing(e) End Sub
Public Sub ServerSyncInvoked(ByVal messageName As String) _ Implements ULServerSyncListener.ServerSyncInvoked
Me.Invoke(New EventHandler(AddressOf Me.ServerSyncAction)) End Sub
Public Sub ServerSyncAction( _ ByVal sender As Object, ByVal e As EventArgs _ ) ' Do Server sync conn.Synchronize() End Sub
End Class
以下 C# 码段介绍如何接收服务器同步请求并在 UI 线程中执行同步。
using iAnywhere.Data.UltraLite;
public class Form1 : System.Windows.Forms.Form, ULServerSyncListener
{
private System.Windows.Forms.MainMenu mainMenu1;
private ULConnection conn;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after
// InitializeComponent call
//
ULConnection.DatabaseManager.SetServerSyncListener(
"myCompany.mymsg", "myCompany.myapp", this
);
// Create connection
...
}
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
protected override void OnClosing(
System.ComponentModel.CancelEventArgs e)
{
ULConnection.DatabaseManager.SetServerSyncListener(
null, null, null
);
base.OnClosing(e);
}
public void ServerSyncInvoked( string messageName )
{
this.Invoke( new EventHandler( ServerSyncHandler ) );
}
internal void ServerSyncHandler(object sender, EventArgs e)
{
conn.Synchronize();
}
}