다음을 통해 공유


SqlCeReplication.CancelSynchronize Method

BeginSynchronize 메서드를 호출하여 시작된 비동기 데이터 동기화의 진행을 취소합니다.

네임스페이스: System.Data.SqlServerCe
어셈블리: System.Data.SqlServerCe(system.data.sqlserverce.dll에 있음)

구문

‘선언
Public Sub CancelSynchronize
public void CancelSynchronize ()
public:
void CancelSynchronize ()
public void CancelSynchronize ()
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();
    }
}

스레드 보안

이 유형의 모든 public static(Microsoft Visual Basic의 경우 공유) 멤버는 스레드로부터 안전합니다. 인스턴스 멤버는 스레드로부터의 안전성이 보장되지 않습니다.

플랫폼

개발 플랫폼

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
버전 정보
.NET Framework 및 NET Compact Framework
3.5에서 지원됨
.NET Framework
3.0에서 지원됨
.NET Compact Framework 및 .Net Framework
2.0에서 지원됨

참고 항목

참조

SqlCeReplication Class
SqlCeReplication Members
System.Data.SqlServerCe Namespace