SqlCeReplication.BeginSynchronize Method (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
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
Parâmetros
- onSyncCompletion
Os representantes de IAsyncResult que são implementados pelo chamador e chamados no final da sincronização.
- state
Um objeto definido pelo usuário que é retornado pela propriedade AsyncState.
Valor de retorno
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.
Exemplo
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();
}
}
Segurança de thread
Quaisquer membros estáticos públicos (compartilhados no Microsoft Visual Basic) desse tipo são thread safe. Não há garantia de que qualquer membro de instância seja thread safe.
Plataformas
Plataformas de desenvolvimento
Windows Vista, Windows Mobile 5.0, Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Mobile 2003 for Pocket PC, Windows CE 5.0
Informações de versão
.NET Framework e NET Compact Framework
Com suporte no 3.5
.NET Framework
Com suporte no 3.0
.NET Compact Framework e .Net Framework
Com suporte no 2.0
Consulte também
Referência
SqlCeReplication Class
SqlCeReplication Members
System.Data.SqlServerCe Namespace