RecognizerContext.BackgroundRecognizeWithAlternates 方法 (Object)

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

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

语法

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

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

参数

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

备注

此方法指定以异步方式执行墨迹识别。

若要执行仅包含排列在最前面的备选项的识别,请调用 BackgroundRecognize 方法。

如果识别器未识别任何备选项,则不引发 RecognitionWithAlternates 事件。

示例

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

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

Private Sub mInkOverlay_Stroke3(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.BackgroundRecognizeWithAlternates(DateTime.Now)
End Sub
private void mInkOverlay_Stroke3(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.BackgroundRecognizeWithAlternates(DateTime.Now);
}

完成后台识别时将激发 RecognitionWithAlternates 事件。在处理此事件的过程中,会将识别结果(包括备选项)放入一个列表框。此外,还将从 RecognizerContextRecognitionWithAlternatesEventArgs 对象的 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 成员

BackgroundRecognizeWithAlternates 重载

Microsoft.Ink 命名空间

BackgroundRecognizeWithAlternates

RecognizerContext.BackgroundRecognize

ExtendedProperty.Data

RecognitionAlternate