SqlCeReplication.BeginSynchronize Method (AsyncCallback, Object)
Démarre une opération de synchronisation de données asynchrones. À la fin de la synchronisation, les délégués AsyncCallback sont appelés. Aucun rapport d'état n'est créé au cours de la synchronisation.
Espace de noms: System.Data.SqlServerCe
Assembly: System.Data.SqlServerCe (dans system.data.sqlserverce.dll)
Syntaxe
'Déclaration
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
Paramètres
- onSyncCompletion
Délégués IAsyncResult implémentés par l'appelant et appelés à la fin de la synchronisation.
- state
Objet défini par l'utilisateur qui est retourné par la propriété AsyncState.
Valeur de retour
Interface IAsyncResult pour l'opération asynchrone qui a été démarrée en appelant cette fonction. Vous pouvez utiliser cette interface pour tester l'achèvement, ou attendre que la synchronisation soit terminée.
Remarques
Pour plus d'informations sur la synchronisation de données asynchrones dans SQL Server Compact 3.5, consultez la rubrique « Asynchronous Data Synchronization » de la documentation en ligne de SQL Server Compact 3.5.
Exemple
L'exemple suivant montre comment configurer la réplication SQL Server Compact 3.5 pour effectuer une synchronisation de données asynchrones.
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();
}
}
Sécurité des threads
Tout membre statique public (Partagé dans Microsoft Visual Basic) de ce type sont thread-safe. Tous les membres de l'instance ne sont pas garantis comme sûrs.
Plateformes
Plateformes de développement
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
Informations sur la version
.NET Framework et NET Compact Framework
Pris en charge dans 3.5
.NET Framework
Pris en charge dans 3.0
.NET Compact Framework et .Net Framework
Pris en charge dans 2.0
Voir aussi
Référence
SqlCeReplication Class
SqlCeReplication Members
System.Data.SqlServerCe Namespace