CancelSynchronize 方法
取消正在進行的非同步的資料同步處理,此作業是藉由呼叫 BeginSynchronize 方法而啟動。
命名空間: System.Data.SqlServerCe
組件: System.Data.SqlServerCe (在 System.Data.SqlServerCe.dll 中)
語法
'宣告
Public Sub CancelSynchronize
'用途
Dim instance As SqlCeReplication
instance.CancelSynchronize()
public void CancelSynchronize()
public:
void CancelSynchronize()
member CancelSynchronize : unit -> unit
public function CancelSynchronize()
備註
取消同步處理會當做錯誤回報,錯誤碼為 SSCE_M_SYNCCANCELED。取消同步處理只會取消用戶端作業,並不會傳送任何要求來取消正在進行的伺服器作業。
如需有關 SQL Server Compact 3.5 中非同步資料同步處理的詳細資訊,請參閱《SQL Server Compact 3.5 線上叢書》內的<非同步資料同步處理>。
範例
下列範例顯示如何取消進行中的資料同步處理。
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();
}
}