AnnotationStore.Flush Method ()

 

Forces any annotation data retained in internal buffers to be written to the underlying storage device.

Namespace:   System.Windows.Annotations.Storage
Assembly:  PresentationFramework (in PresentationFramework.dll)

public abstract void Flush()

Exception Condition
ObjectDisposedException

Dispose has been called on the store.

Applications that use an explicit-save model can set AutoFlush to false and call Flush directly when appropriate.

Applications that use an implicit-save model can set the AutoFlush to true to cause Flush to be called automatically after every store operation (add, delete, or modify).

The following example shows how to use the Flush method when the application closes the 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()

The following example shows use of the DeleteAnnotation and Flush methods.

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

.NET Framework
Available since 3.0
Return to top
Show: