BeginSynchronize メソッド (AsyncCallback, Object)
非同期データの同期操作を開始します。同期が終了すると、AsyncCallback デリゲートが呼び出されます。同期中には、ステータス レポートが実行されません。
名前空間: System.Data.SqlServerCe
アセンブリ: System.Data.SqlServerCe (System.Data.SqlServerCe.dll)
構文
'宣言
Public Function BeginSynchronize ( _
onSyncCompletion As AsyncCallback, _
state As Object _
) As IAsyncResult
'使用
Dim instance As SqlCeReplication
Dim onSyncCompletion As AsyncCallback
Dim state As Object
Dim returnValue As IAsyncResult
returnValue = instance.BeginSynchronize(onSyncCompletion, _
state)
public IAsyncResult BeginSynchronize(
AsyncCallback onSyncCompletion,
Object state
)
public:
IAsyncResult^ BeginSynchronize(
AsyncCallback^ onSyncCompletion,
Object^ state
)
member BeginSynchronize :
onSyncCompletion:AsyncCallback *
state:Object -> IAsyncResult
public function BeginSynchronize(
onSyncCompletion : AsyncCallback,
state : Object
) : IAsyncResult
パラメーター
- onSyncCompletion
型: System. . :: . .AsyncCallback
呼び出し元によって実装され、同期の最後に呼び出される IAsyncResult デリゲート。
- state
型: System. . :: . .Object
AsyncState プロパティによって返されるユーザー定義のオブジェクト。
戻り値
型: System. . :: . .IAsyncResult
この関数を呼び出すことによって開始される非同期操作の IAsyncResult インターフェイス。このインターフェイスを使用して、完了テストを実行したり、同期が終了するまで待機したりできます。
説明
SQL Server Compact 3.5 における非同期データの同期化の詳細については、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();
}
}