在 ActiveSync 的 MobiLink 提供程序调用应用程序执行同步时被调用。
Visual Basic Public Sub ActiveSyncInvoked( _ ByVal launchedByProvider As Boolean _ )
C# public void ActiveSyncInvoked( bool launchedByProvider );
launchedByProvider 如果是由 MobiLink 提供程序启动应用程序来执行 ActiveSync 同步,则为 true。应用程序在完成同步后必须自行关闭。如果当用于 ActiveSync 的 MobiLink 提供程序调用应用程序时,该应用程序已经在运行,则为 false。
此方法由单独的线程调用。为避免多线程问题,它应向 UI 发布一个事件。如果您正在使用多线程,建议您使用一个单独的连接,并使用 lock 关键字来访问与应用程序的其余部分共享的所有对象。
完成同步后,应用程序应调用 ULDatabaseManager.SignalSyncIsComplete() 向 ActiveSync 的 MobiLink 提供程序发出信号。
以下代码段演示了如何在 UI 线程中接收 ActiveSync 请求并执行同步。
' 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 _ ) ' Do active sync conn.Synchronize() ULConnection.DatabaseManager.SignalSyncIsComplete() End Sub End Class |
// 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 // 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(); } } |
Copyright © 2009, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.1 |