SyncOrchestrator.Synchronize 方法

启动同步会话。

命名空间: Microsoft.Synchronization
程序集: Microsoft.Synchronization(在 microsoft.synchronization.dll 中)

语法

声明
Public Function Synchronize As SyncOperationStatistics
用法
Dim instance As SyncOrchestrator
Dim returnValue As SyncOperationStatistics

returnValue = instance.Synchronize
public SyncOperationStatistics Synchronize ()
public:
SyncOperationStatistics^ Synchronize ()
public SyncOperationStatistics Synchronize ()
public function Synchronize () : SyncOperationStatistics

返回值

有关同步会话的统计信息。

备注

此方法执行的同步既有可能是单向的,也有可能是双向的,具体取决于 Direction 的值。

调用此方法时,LocalProviderRemoteProvider 都不能为 null 引用(在 Visual Basic 中为 Nothing)。

此方法对 State 进行设置,以便与 Direction 的值相对应。

示例

下面的示例在两个提供程序之间同步数据并向用户显示同步统计信息。

    ' Create the synchronization orchestrator and set the providers and synchronization direction.
    Dim orchestrator As New SyncOrchestrator()
    orchestrator.LocalProvider = localProvider
    orchestrator.RemoteProvider = remoteProvider
    orchestrator.Direction = syncDir

    Dim msg As String
    Try
        ' Synchronize data between the two providers.
        Dim stats As SyncOperationStatistics = orchestrator.Synchronize()

        ' Display statistics for the synchronization operation.
        msg = ((("Synchronization succeeded!" & vbLf & vbLf & stats.DownloadChangesApplied & " download changes applied" & vbLf) & stats.DownloadChangesFailed & " download changes failed" & vbLf) & stats.UploadChangesApplied & " upload changes applied" & vbLf) & stats.UploadChangesFailed & " upload changes failed"
    Catch ex As Exception
        msg = "Synchronization failed! Here's why: " & vbLf & vbLf & ex.Message
    End Try
    MessageBox.Show(msg, "Synchronization Results")
End Sub
    // Create the synchronization orchestrator and set the providers and synchronization direction.
    SyncOrchestrator orchestrator = new SyncOrchestrator();
    orchestrator.LocalProvider = localProvider;
    orchestrator.RemoteProvider = remoteProvider;
    orchestrator.Direction = syncDir;

    string msg;
    try
    {
        // Synchronize data between the two providers.
        SyncOperationStatistics stats = orchestrator.Synchronize();

        // Display statistics for the synchronization operation.
        msg = "Synchronization succeeded!\n\n" +
            stats.DownloadChangesApplied + " download changes applied\n" +
            stats.DownloadChangesFailed + " download changes failed\n" +
            stats.UploadChangesApplied + " upload changes applied\n" +
            stats.UploadChangesFailed + " upload changes failed";
    }
    catch (Exception ex)
    {
        msg = "Synchronization failed! Here's why: \n\n" + ex.Message;
    }
    MessageBox.Show(msg, "Synchronization Results");
}

请参阅

参考

SyncOrchestrator 类
SyncOrchestrator 成员
Microsoft.Synchronization 命名空间