DynamicRenderer.ReleaseCachedData (Método)

Actualización: noviembre 2007

Libera los datos del lápiz de Tablet PC de la memoria caché del objeto DynamicRenderer.

Espacio de nombres:  Microsoft.StylusInput
Ensamblado:  Microsoft.Ink (en Microsoft.Ink.dll)

Sintaxis

'Declaración
Public Sub ReleaseCachedData ( _
    cachedDataId As Integer _
)
'Uso
Dim instance As DynamicRenderer
Dim cachedDataId As Integer

instance.ReleaseCachedData(cachedDataId)
public void ReleaseCachedData(
    int cachedDataId
)
public:
void ReleaseCachedData(
    int cachedDataId
)
public void ReleaseCachedData(
    int cachedDataId
)
public function ReleaseCachedData(
    cachedDataId : int
)

Parámetros

  • cachedDataId
    Tipo: System.Int32
    Identificador de los datos que se van a liberar.

Comentarios

Este método sólo se usa cuando la propiedad EnableDataCache se establece en true.

Al establecer la propiedad EnableDataCache en true, se puede controlar el hecho de que los procesos lentos bloqueen la cola de salida. Si pasa un tiempo desde que el objeto DynamicRenderer dibuja los trazos hasta que se invalida la ventana, es posible que haya que esperar hasta que se puedan volver a dibujar los trazos recopilados. Al colocar los trazos de DynamicRenderer en una memoria caché, los éstos pueden volver a dibujarse mediante una llamada al método Refresh. No obstante, una vez recopilados los trazos, deben liberarse de la memoria caché mediante una llamada al método ReleaseCachedData. Generalmente, la liberación se produce en el método CustomStylusDataAdded.

Otra circunstancia en que es útil establecer la propiedad EnableDataCache en true es cuando se desea mostrar los trazos a medida que se dibujan, pero una vez que se haya hecho algo con ellos, ya no es necesario almacenarlos. En este caso, almacene los identificadores de datos en el parámetro data del método CustomStylusDataAdded y, después, libere los datos cuando ya no necesite los trazos almacenados en memoria caché.

Ejemplos

Este ejemplo de C# amplía el ejemplo RealTimeStylus Ink Collection Sample que se proporciona en la sección relativa a la Tecnología táctil y Tablet PC del SDK de Windows. Tras habilitar DynamicRenderer, theDynamicRenderer, la propiedad EnableDataCache se establece en true. La propiedad DataInterest se modifica para que se agregue DataInterestMask. El método CustomStylusDataAdded busca datos con el identificador de campo DynamicRendererCachedDataGuid y, a continuación, los libera mediante la propiedad CachedDataId de los datos.

// ...
private void InkCollection_Load(object sender, System.EventArgs e)
{
    // ...
    
    // Enable the real time stylus and the dynamic renderer
    theRealTimeStylus.Enabled = true;
    theDynamicRenderer.Enabled = true;  

    // Enable caching. If a refresh happens during inking, then
    // the stroke will still be displayed.  However, we have to 
    // release the cached data later.
    theDynamicRenderer.EnableDataCache = true;
    
    // ...
}
// ...
public DataInterestMask DataInterest
{
    get
    {
        return DataInterestMask.StylusDown |
               DataInterestMask.Packets |
               DataInterestMask.StylusUp |
               DataInterestMask.Error |
               DataInterestMask.CustomStylusDataAdded;
    }
}
public void CustomStylusDataAdded(RealTimeStylus sender, CustomStylusData data)
{
    // Release any cached data that's shown up.
    if (data.CustomDataId == DynamicRenderer.DynamicRendererCachedDataGuid)
    {
       DynamicRendererCachedData cachedData = (DynamicRendererCachedData) data.Data;
       cachedData.DynamicRenderer.ReleaseCachedData(cachedData.CachedDataId);
    }
}
// ...

En este ejemplo de C# se colocan los datos de un objeto DynamicRenderer en una memoria caché. De esta forma, se garantiza que una invalidación de ventana no borra los trazos. En el ejemplo los trazos se borran después, mediante programación. Tras habilitar el objeto DynamicRenderer, theDynamicRenderer, la propiedad EnableDataCache se establece en true. En el controlador de eventos Paint, el ejemplo llama a DynamicRenderer.Refresh para volver a dibujar los datos del lápiz de Tablet PC en la memoria caché. La propiedad DataInterest se modifica para que se agregue DataInterestMask. El método CustomStylusDataAdded busca datos con el identificador del campo DynamicRendererCachedDataGuid y almacena el identificador de los datos en un objeto ArrayList, cachedIds. El método ClearStrokes llama a ReleaseCachedData en todos los identificadores de cachedIds y después llama a Refresh en el control.

using Microsoft.StylusInput;
using Microsoft.StylusInput.PluginData;
// ...
public class InkCollection : Form, IStylusAsyncPlugin
{ 
    private RealTimeStylus theRealTimeStylus;
    private DynamicRenderer theDynamicRenderer;
    private ArrayList cachedIds = new ArrayList();
// ...
    private void TempInkCollection_Load(object sender, System.EventArgs e)
    {
        theDynamicRenderer = new DynamicRenderer(this);
        theRealTimeStylus = new RealTimeStylus(this, true);

        // Add the dynamic renderer to the synchronous plugin notification chain.
        // Synchronous notifications occur on the pen thread.
        theRealTimeStylus.SyncPluginCollection.Add(theDynamicRenderer);

        // Add the form to the asynchronous plugin notification chain.  This plugin
        // will be used to collect stylus data into an ink object.  Asynchronous
        // notifications occur on the UI thread.
        theRealTimeStylus.AsyncPluginCollection.Add(this);

        // Enable the real time stylus and the dynamic renderer
        theRealTimeStylus.Enabled = true;
        theDynamicRenderer.Enabled = true;  

        // Enable caching. If a refresh happens during inking, then
        // the stroke will still be displayed.  However, we have to 
        // release the cached data later.
        theDynamicRenderer.EnableDataCache = true;
    }
// ...
    private void InkCollection_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
    {
        // Refresh the dynamic renderer, since it's possible that a stroke is being
        // collected at the time Paint occurs.  In this case, the portion of the stroke
        // that has already been collected will need to be redrawn.
        theDynamicRenderer.ClipRectangle = e.ClipRectangle;
        theDynamicRenderer.Refresh();
    }
// ...
    public DataInterestMask DataInterest
    {
        get
        {
            return DataInterestMask.CustomStylusDataAdded;
        }
    }

    public void CustomStylusDataAdded(RealTimeStylus sender, CustomStylusData data)
    {
        // Release any cached data that's shown up.
        if (data.CustomDataId == DynamicRenderer.DynamicRendererCachedDataGuid)
        {
            DynamicRendererCachedData cachedData = (DynamicRendererCachedData) data.Data;
            cachedIds.Add(cachedData.CachedDataId);
        }
    }
// ...
    private void ClearStrokes()
    {
        // Release all data
        foreach int dataId in cachedIds
        {
            theDynamicRenderer.ReleaseCachedData(dataId);
        }
        // Clear our stored list of Ids
        cachedIds.Clear();
        // Refresh the window
        this.Refresh()
    }
}

En este ejemplo de Microsoft Visual Basic .NET, se colocan los datos de un objeto DynamicRenderer en una memoria caché. De esta forma, se garantiza que una invalidación de ventana no borra los trazos. En el ejemplo los trazos se borran después, mediante programación. Tras habilitar el objeto DynamicRenderer, theDynamicRenderer, la propiedad EnableDataCache se establece en true. En el controlador de eventos Paint, el ejemplo llama a DynamicRenderer.Refresh para volver a dibujar los datos del lápiz de Tablet PC en la memoria caché. La propiedad DataInterest se modifica para que se agregue DataInterestMask. El método CustomStylusDataAdded busca datos con el identificador del campo DynamicRendererCachedDataGuid y almacena el identificador de los datos en un objeto ArrayList, cachedIds. La subrutina ClearStrokes llama a ReleaseCachedData en todos los identificadores de cachedIds y después llama a Refresh en el control.

Imports Microsoft.StylusInput
Imports Microsoft.StylusInput.PluginData
' ...
Public Class TempInkCollector
    Inherits System.Windows.Forms.Form
    Implements Microsoft.StylusInput.IStylusAsyncPlugin

    Private theRealTimeStylus As RealTimeStylus
    Private theDynamicRenderer As DynamicRenderer
    Private cachedIds As ArrayList = New ArrayList()
' ...
    Private Sub TempInkCollector_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        theDynamicRenderer = New DynamicRenderer(Me)
        theRealTimeStylus = New RealTimeStylus(Me, True)

        ' Add the dynamic renderer to the synchronous plugin notification chain.
        ' Synchronous notifications occur on the pen thread.
        theRealTimeStylus.SyncPluginCollection.Add(theDynamicRenderer)

        ' Add the form to the asynchronous plugin notification chain.  This plugin
        ' will be used to collect stylus data into an ink object.  Asynchronous
        ' notifications occur on the UI thread.
        theRealTimeStylus.AsyncPluginCollection.Add(Me)

        ' Enable the real time stylus and the dynamic renderer
        theRealTimeStylus.Enabled = True
        theDynamicRenderer.Enabled = True
        theDynamicRenderer.EnableDataCache = True
    End Sub
' ...
    Private Sub InkCollector_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        ' Refresh the dynamic renderer, since it's possible that a stroke is being
        ' collected at the time Paint occurs.  In this case, the portion of the stroke
        ' that has already been collected will need to be redrawn.
        theDynamicRenderer.ClipRectangle = e.ClipRectangle
        theDynamicRenderer.Refresh()
    End Sub
'...
    Overridable Overloads ReadOnly Property DataInterest() As DataInterestMask Implements IStylusAsyncPlugin.DataInterest
        Get
            Return DataInterestMask.CustomStylusDataAdded
        End Get
    End Property
    Public Sub CustomStylusDataAdded(ByVal sender As Microsoft.StylusInput.RealTimeStylus, ByVal data As Microsoft.StylusInput.PluginData.CustomStylusData) Implements Microsoft.StylusInput.IStylusAsyncPlugin.CustomStylusDataAdded
        If data.CustomDataId.Equals(DynamicRenderer.DynamicRendererCachedDataGuid) Then
            ' Convert to DynamicRendererCachedData
            Dim cachedData As DynamicRendererCachedData = data.Data
            ' Add to list of ids.
            cachedIds.Add(cachedData.CachedDataId)
        End If
    End Sub
' ...
    Private Sub ClearStrokes()
        ' Release all data
        Dim dataId As Integer
        For Each dataId In cachedIds
            theDynamicRenderer.ReleaseCachedData(dataId)
        Next
        ' Clear our stored list of Ids
        cachedIds.Clear()
        ' Refresh the window
        Me.Refresh()
    End Sub
End Class

Plataformas

Windows Vista, Windows XP SP2, Windows Server 2003

.NET Framework y .NET Compact Framework no admiten todas las versiones de cada plataforma. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.

Información de versión

.NET Framework

Compatible con: 3.0

Vea también

Referencia

DynamicRenderer (Clase)

DynamicRenderer (Miembros)

Microsoft.StylusInput (Espacio de nombres)

DynamicRenderer.EnableDataCache

DynamicRenderer.Refresh

DynamicRendererCachedData

Otros recursos

Dynamic-Renderer Plug-ins