SqlCeReplication.CancelSynchronize Method
Annule une synchronisation de données asynchrones en cours qui a été démarrée par un appel à la méthode BeginSynchronize.
Espace de noms: System.Data.SqlServerCe
Assembly: System.Data.SqlServerCe (dans system.data.sqlserverce.dll)
Syntaxe
'Déclaration
Public Sub CancelSynchronize
public void CancelSynchronize ()
public:
void CancelSynchronize ()
public void CancelSynchronize ()
public function CancelSynchronize ()
Remarques
L'annulation de la synchronisation est signalée en tant qu'erreur avec le code d'erreur SSCE_M_SYNCCANCELED. L'annulation de la synchronisation annule uniquement l'opération côté client ; elle n'envoie pas de demande d'annulation de l'opération serveur en cours.
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 annuler une synchronisation de données en cours.
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