Condividi tramite


Metodo BeginSynchronize (AsyncCallback, Object)

Consente di avviare un'operazione di sincronizzazione dei dati asincroni. Al termine della sincronizzazione vengono chiamati i delegati AsyncCallback. Durante la sincronizzazione non viene fornito alcun report sullo stato.

Spazio dei nomi:  System.Data.SqlServerCe
Assembly:  System.Data.SqlServerCe (in System.Data.SqlServerCe.dll)

Sintassi

'Dichiarazione
Public Function BeginSynchronize ( _
    onSyncCompletion As AsyncCallback, _
    state As Object _
) As IAsyncResult
'Utilizzo
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

Parametri

Valore restituito

Tipo: System. . :: . .IAsyncResult
Interfaccia IAsyncResult per l'operazione asincrona avviata mediante la chiamata di questa funzione. Utilizzare questa interfaccia per verificare il completamento o attendere il termine della sincronizzazione.

Osservazioni

Per ulteriori informazioni sulla sincronizzazione di dati asincroni in SQL Server Compact 3.5, vedere "Asynchronous Data Synchronization" (Sincronizzazione di dati asincroni) nella documentazione online di SQL Server Compact 3.5.

Esempi

Nell'esempio seguente vengono illustrate le modalità di impostazione della replica di SQL Server Compact 3.5 per eseguire la sincronizzazione di dati asincroni.

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();
    }
}

Vedere anche

Riferimento

SqlCeReplication Classe

Membri SqlCeReplication

Overload BeginSynchronize

Spazio dei nomi System.Data.SqlServerCe