Partilhar via


Método BeginSynchronize (AsyncCallback, Object)

Inicia uma operação de sincronização de dados assíncronos. Quando a sincronização é encerrada, os representantes de AsyncCallback são chamados. Durante a sincronização, nenhum relatório de status é executado.

Namespace:  System.Data.SqlServerCe
Assembly:  System.Data.SqlServerCe (em System.Data.SqlServerCe.dll)

Sintaxe

'Declaração
Public Function BeginSynchronize ( _
    onSyncCompletion As AsyncCallback, _
    state As Object _
) As IAsyncResult
'Uso
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
)
member BeginSynchronize : 
        onSyncCompletion:AsyncCallback * 
        state:Object -> IAsyncResult 
public function BeginSynchronize(
    onSyncCompletion : AsyncCallback, 
    state : Object
) : IAsyncResult

Parâmetros

Valor de retorno

Tipo: System. . :: . .IAsyncResult
A interface IAsyncResult para a operação assíncrona que foi iniciada chamando essa função. Você pode usar essa interface para testar a conclusão ou aguardar o final de sincronização.

Comentários

Para obter informações sobre a sincronização de dados assíncronos no SQL Server Compact 3.5, consulte "Sincronização de dados assíncronos" nos Manuais Online do SQL Server Compact 3.5.

Exemplos

O exemplo a seguir mostra como configurar a replicação do SQL Server Compact 3.5 para executar a sincronização de dados assíncronos.

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
        '
        'NOTE: when possible, prompt users to enter security 
        'credentials at runtime. If you store credentials in a file, 
        'you must secure the file to prevent unauthorized access.
        '
        repl = New SqlCeReplication( _
            "https://www.adventure-works.com/sqlmobile/sqlcesa35.dll", _
            "MyInternetLogin", _
            "<enterStrongPassword>", _
            "MyPublisher", _
            "MyPublisherDatabase", _
            "MyPublisherLogin", _
            "<enterStrongPassword>", _
            "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
        //
        //NOTE: when possible, prompt users to enter security 
        //credentials at runtime. If you store credentials in a file, 
        //you must secure the file to prevent unauthorized access.
        //
        repl = new SqlCeReplication(
            "https://www.adventure-works.com/sqlmobile/sqlcesa35.dll",
            "MyInternetLogin",
            "<enterStrongPassword>",
            "MyPublisher",
            "MyPublisherDatabase",
            "MyPublisherLogin",
            "<enterStrongPassword>",
            "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();
    }
}

Consulte também

Referência

SqlCeReplication Classe

Membros SqlCeReplication

Sobrecarga BeginSynchronize

Namespace System.Data.SqlServerCe