RecognizerContext.BackgroundRecognize 方法 (Object)

使 Recognizer 对象识别关联的 Strokes 集合,并在完成识别时引发包含关联的应用程序数据的 Recognition 事件。

命名空间:  Microsoft.Ink
程序集:  Microsoft.Ink(在 Microsoft.Ink.dll 中)

语法

声明
Public Sub BackgroundRecognize ( _
    customData As Object _
)
用法
Dim instance As RecognizerContext
Dim customData As Object

instance.BackgroundRecognize(customData)
public void BackgroundRecognize(
    Object customData
)
public:
void BackgroundRecognize(
    Object^ customData
)
public void BackgroundRecognize(
    Object customData
)
public function BackgroundRecognize(
    customData : Object
)

参数

  • customData
    类型:System.Object
    Recognition 事件中可用于应用程序的任何应用程序定义的数据。默认值为 null(在 Microsoft(R) Visual Basic(R) .NET 中为 Nothing)。

备注

此方法指定以异步方式执行墨迹识别。若要以同步方式识别墨迹,请调用 RecognizerContext.Recognize 方法。

此方法仅识别最佳结果字符串。此方法不创建 RecognitionAlternate 对象。若要执行创建可用备选项列表的识别,请调用 BackgroundRecognizeWithAlternates 方法。

如果识别器未识别任何内容,则不引发 Recognition 事件。

示例

此示例自动识别在 InkOverlay 对象中创建的每个笔画,并显示识别结果。

在激发 Stroke 事件(对用户完成笔画做出的响应)时,会将新创建的笔画添加到 RecognizerContext 对象的 Strokes 集合中,并调用 BackgroundRecognize 方法,调用时将当前时间传递给 customData 参数。

Private Sub mInkOverlay_Stroke4(ByVal sender As Object, ByVal e As InkCollectorStrokeEventArgs)
    ' in case background recognition is still occurring, stop it
    mRecognizerContext.StopBackgroundRecognition()
    ' add the stroke, and start recognition
    mRecognizerContext.Strokes.Add(e.Stroke)
    mRecognizerContext.BackgroundRecognize(DateTime.Now)
End Sub
private void mInkOverlay_Stroke4(object sender, InkCollectorStrokeEventArgs e)
{
    // in case background recognition is still occurring, stop it
    mRecognizerContext.StopBackgroundRecognition();
    // add the stroke, and start recognition, passing current time
    mRecognizerContext.Strokes.Add(e.Stroke);
    mRecognizerContext.BackgroundRecognize(DateTime.Now);
}

完成后台识别时将激发 Recognition 事件。在处理此事件的过程中,会将识别结果放入一个列表框。此外,还将从 RecognizerContextRecognitionEventArgs 对象的 CustomData 属性检索识别的起始时间,并使用该时间计算识别所需的总时间。

' event fires when recognition results (without alternates) are ready
Private Sub RecognizerContext_Recognition(ByVal sender As Object, _
            ByVal e As RecognizerContextRecognitionEventArgs)
    ' when updating a control, must use Invoke() since controls are
    ' not thread safe and recognition occurs on a different thread
    If Me.InvokeRequired Then
        ' recursively call this method via Invoke()
        Me.Invoke( _
            New RecognizerContextRecognitionEventHandler(AddressOf RecognizerContext_Recognition), _
            New Object() {sender, e} _
        )
        Return
    End If
    If RecognitionStatus.NoError = e.RecognitionStatus Then
        listBoxRecognitionResults.Items.Add(e.Text)
        ' get the custom data and calculate elapsed time
        Dim startTime As DateTime = DirectCast(e.CustomData, DateTime)
        Dim endTime As DateTime = DateTime.Now
        Dim span As TimeSpan = New TimeSpan(endTime.Ticks - startTime.Ticks)
        ' display the number of seconds for this recognition to finish
        listBoxRecognitionResults.Items.Add(span.TotalSeconds.ToString())
    End If
End Sub
// event fires when recognition results (without alternates) are ready
private void RecognizerContext_Recognition(object sender, RecognizerContextRecognitionEventArgs e)
{
    // when updating a control, must use Invoke() since controls are
    // not thread safe and recognition occurs on a different thread
    if (this.InvokeRequired)
    {
        // recursively call this method via Invoke()
        this.Invoke(
            new RecognizerContextRecognitionEventHandler(RecognizerContext_Recognition),
            new object[] { sender, e }
            );
        return;
    }

    if (RecognitionStatus.NoError == e.RecognitionStatus)
    {
        listBoxRecognitionResults.Items.Add(e.Text);
        // get the custom data and calculate elapsed time
        DateTime startTime = (DateTime)e.CustomData;
        DateTime endTime = DateTime.Now;
        TimeSpan span = new TimeSpan(endTime.Ticks - startTime.Ticks);
        // display the number of seconds for this recognition to finish
        listBoxRecognitionResults.Items.Add(span.TotalSeconds.ToString());
    }
}

平台

Windows Vista

.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求

版本信息

.NET Framework

受以下版本支持:3.0

另请参见

参考

RecognizerContext 类

RecognizerContext 成员

BackgroundRecognize 重载

Microsoft.Ink 命名空间

RecognizerContext.BackgroundRecognizeWithAlternates

ExtendedProperty.Data

RecognitionAlternate