Compartilhar via


SqlCeReplication.BeginSynchronize Method (AsyncCallback, Object)

Starts an asynchronous data synchronization operation. When synchronization ends, the AsyncCallback delegates are called. During synchronization, no status reporting is performed.

Namespace: System.Data.SqlServerCe
Assembly: System.Data.SqlServerCe (in system.data.sqlserverce.dll)

Syntax

'Declaration
Public Function BeginSynchronize ( _
    onSyncCompletion As AsyncCallback, _
    state As Object _
) As IAsyncResult
'Usage
Dim instance As SqlCeReplication
Dim onSyncCompletion As AsyncCallback
Dim state As Object
Dim returnValue As IAsyncResult

returnValue = instance.BeginSynchronize(onSyncCompletion, state)
public IAsyncResult BeginSynchronize (
    AsyncCallback onSyncCompletion,
    Object state
)
public:
IAsyncResult^ BeginSynchronize (
    AsyncCallback^ onSyncCompletion, 
    Object^ state
)
public IAsyncResult BeginSynchronize (
    AsyncCallback onSyncCompletion, 
    Object state
)
public function BeginSynchronize (
    onSyncCompletion : AsyncCallback, 
    state : Object
) : IAsyncResult
Not applicable.

Parameters

  • onSyncCompletion
    The IAsyncResult delegates that are implemented by the caller and called at the end of synchronization.
  • state
    A user-defined object that is returned by the AsyncState property.

Return Value

The IAsyncResult interface for the asynchronous operation that has been started by calling this function. You can use this interface for testing for completion, or waiting until synchronization ends.

Remarks

For information about asynchronous data synchronization in SQL Server Compact Edition, see "Asynchronous Data Synchronization" in the SQL Server Compact Edition Books Online.

Example

The following example shows how to set up SQL Server Compact Edition replication to perform 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();
    }
}

Platforms

Windows CE, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows XP Professional x64 Edition, Windows XP SP2

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

Version Information

.NET Framework

Supported in: 3.0

.NET Compact Framework

Supported in: 2.0

See Also

Reference

SqlCeReplication Class
SqlCeReplication Members
System.Data.SqlServerCe Namespace