AnnotationStore.Flush 方法

定義

強制將保留在內部緩衝區中的註解資料寫入底層儲存裝置。

public:
 abstract void Flush();
public abstract void Flush();
abstract member Flush : unit -> unit
Public MustOverride Sub Flush ()

例外狀況

Dispose 已經被叫去店裡了。

範例

以下範例說明當應用程式關閉 時Flush如何使用該AnnotationService方法。

// -------------------------- StopAnnotations -------------------------
/// <summary>
///   Disables annotations processing and hides annotations.</summary>
public void StopAnnotations()
{
    // If the AnnotationStore is active, flush and close it.
    if ( (_annotService != null) && _annotService.IsEnabled )
    {
        _annotService.Store.Flush();
        _annotStream.Flush();
        _annotStream.Close();
    }

    // If the AnnotationService is active, shut it down.
    if (_annotService != null)
    {
        if (_annotService.IsEnabled)
            _annotService.Disable();
        _annotService = null;
    }
}// end:StopAnnotations()
' -------------------------- StopAnnotations -------------------------
''' <summary>
'''   Disables annotations processing and hides annotations.</summary>
Public Sub StopAnnotations()
    ' If the AnnotationStore is active, flush and close it.
    If (_annotService IsNot Nothing) AndAlso _annotService.IsEnabled Then
        _annotService.Store.Flush()
        _annotStream.Flush()
        _annotStream.Close()
    End If

    ' If the AnnotationService is active, shut it down.
    If _annotService IsNot Nothing Then
        If _annotService.IsEnabled Then
            _annotService.Disable()
        End If
        _annotService = Nothing
    End If
End Sub

以下範例展示了 和 DeleteAnnotation 方法的Flush使用。

// ------------------------- DeleteMark_Click -------------------------
void DeleteMark_Click(object sender, RoutedEventArgs e)
{
    Annotation ann = ((MenuItem)sender).Tag as Annotation;
    _annStore.DeleteAnnotation(ann.Id);
    _annStore.Flush();

    MenuItem thisMenu = sender as MenuItem;
    ContextMenu parentMenu = thisMenu.Parent as ContextMenu;
    FrameworkElement dObj =
        parentMenu.PlacementTarget as FrameworkElement;
    while (!(dObj is StackPanel))
    {
        dObj = dObj.Parent as FrameworkElement;
    }

    ListBox collection = dObj.Parent as ListBox;
    collection.Items.Remove(dObj);
    Util.FlushDispatcher();
}

備註

使用明確儲存模型的應用程式可以在 AutoFlush 適當時設定並 false 直接呼叫 Flush

使用隱式儲存模型的應用程式可以設定 AutoFlush to true 導致 Flush 在每次儲存操作(新增、刪除或修改)後自動呼叫。

適用於

另請參閱