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