SqlCeReplication.CancelSynchronize 方法

取消一个正在进行的、通过调用 BeginSynchronize 方法启动的异步数据同步。

命名空间: System.Data.SqlServerCe
程序集: System.Data.SqlServerCe(在 system.data.sqlserverce.dll 中)

语法

声明
Public Sub CancelSynchronize
用法
Dim instance As SqlCeReplication

instance.CancelSynchronize
public void CancelSynchronize ()
public:
void CancelSynchronize ()
public void CancelSynchronize ()
public function CancelSynchronize ()
不适用。

备注

取消同步被报告为一条错误,错误代码是 SSCE_M_SYNCCANCELED。取消同步只取消客户端操作,它不会发送任何要取消正在进行的服务器操作的请求。

有关在 SQL Server Compact Edition 中实现异步数据同步的信息,请参见 SQL Server Compact Edition Books Online(《SQL Server Compact Edition 联机丛书》)中的“Asynchronous Data Synchronization”(异步数据的同步)。

示例

下面的示例演示如何取消正在进行的数据同步。

Public Sub SyncCompletedCallback(ByVal ar As IAsyncResult)
    Try
        Dim repl As SqlCeReplication = CType(ar.AsyncState, SqlCeReplication)

        ' Complete the asynchronous sync and test for errors
        '
        repl.EndSynchronize(ar)
    Catch
        ' Handle errors here
        '
    End Try

End Sub 'SyncCompletedCallback

Public Sub Test()
    Dim repl As SqlCeReplication = Nothing

    Try
        ' Set the Replication object
        '
        repl = New SqlCeReplication( _
            "https://www.adventure-works.com/sqlmobile/sqlcesa30.dll", _
            "MyInternetLogin", _
            "<password>", _
            "MyPublisher", _
            "MyPublisherDatabase", _
            "MyPublisherLogin", _
            "<password>", _
            "MyPublication", _
            "MySubscriber", _
            "Data Source=MyDatabase.sdf")

        ' Begin asynchronous sync; This call returns immediately 
        '
        Dim ar As IAsyncResult = repl.BeginSynchronize( _
            New AsyncCallback(AddressOf SyncCompletedCallback), _
            repl)

        Thread.Sleep(3000)

        ' Cancel the sync if it didn't complete in 3 seconds; normally,
        ' this is hooked up to a button's Click event
        '
        repl.CancelSynchronize()
    Catch
        ' Handle errors here
    Finally
        ' Dispose the repl object
        '
        repl.Dispose()
    End Try

End Sub 'Test
public void SyncCompletedCallback(IAsyncResult ar)
{
    try
    {
        SqlCeReplication repl = (SqlCeReplication)ar.AsyncState;

        // Complete the asynchronous sync and test for errors
        //
        repl.EndSynchronize(ar);
    }
    catch (SqlCeException)
    {
        // Handle errors here
        //
    }
}

public void Test()
{
    SqlCeReplication repl = null;

    try
    {
        // Set the Replication object
        //
        repl = new SqlCeReplication(
            "https://www.adventure-works.com/sqlmobile/sqlcesa30.dll",
            "MyInternetLogin",
            "<password>",
            "MyPublisher",
            "MyPublisherDatabase",
            "MyPublisherLogin",
            "<password>",
            "MyPublication",
            "MySubscriber",
            "Data Source=MyDatabase.sdf");

        // Begin asynchronous sync; This call returns immediately 
        //
        IAsyncResult ar = repl.BeginSynchronize(
            new AsyncCallback(SyncCompletedCallback),
            repl);

        Thread.Sleep(3000);

        // Cancel the sync if it didn't complete in 3 seconds; normally,
        // this is hooked up to a button's Click event
        //
        repl.CancelSynchronize();
    }
    catch (SqlCeException)
    {
        // Handle errors here
    }
    finally
    {
        // Dispose the repl object
        //
        repl.Dispose();
    }
}

平台

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

Windows Vista、Microsoft Windows XP SP2 和 Windows Server 2003 SP1 支持 Microsoft .NET Framework 3.0。

版本信息

.NET Framework

受以下版本支持:3.0

.NET Compact Framework

受以下版本支持:2.0

请参见

参考

SqlCeReplication 类
SqlCeReplication 成员
System.Data.SqlServerCe 命名空间