Share via


StopBackgroundRecognition Method

StopBackgroundRecognition Method

Ends background recognition that was started with a call to BackgroundRecognize or BackgroundRecognizeWithAlternates.

Declaration

[C++]

HRESULT StopBackgroundRecognition ();
      

[Microsoft® Visual Basic® 6.0]

Public Sub StopBackgroundRecognition()
      

Return Value

HRESULT value Description
S_OK Success.

This method also returns S_OK if the recognizer does not support this method.

E_OUTOFMEMORY Cannot allocate memory to complete the operation.
E_INK_EXCEPTION An exception occurred inside method.

Remarks

No event is fired if StopBackgroundRecognition is called.

Call StopBackgroundRecognition if you call BackgroundRecognize or BackgroundRecognizeWithAlternates one or more times. Calling StopBackgroundRecognition does not necessarily ensure that you get no results from a recognition process that is currently under way. It only ensures that all previous calls to BackgroundRecognize or BackgroundRecognizeWithAlternates that have not yet been processed are actually not executed.

Call this method only if you process the ink asynchronously.

Example

[Visual Basic 6.0]

This Visual Basic 6.0 example shows a button handler that halts background recognition of the ink in an InkRecognizerContext, which was started in a stroke event handler.

Option Explicit
Dim WithEvents theInkCollector As InkCollector
Dim WithEvents theRecognizerContext As InkRecognizerContext
Dim theRecognitionResult As IInkRecognitionResult
Dim theStrokes As InkStrokes
Dim isRecognizingInBackground As Boolean

Private Sub ButtonStop_Click()
    If isRecognizingInBackground Then
        theRecognizerContext.StopBackgroundRecognition
        isRecognizingInBackground = False
    End If
End Sub

Private Sub Form_Load()
    'Initialize the InkCollector
    Set theInkCollector = New InkCollector
    theInkCollector.hWnd = Me.hWnd
    theInkCollector.Enabled = True
    'Create new RecognizerContext
    Dim theRecognizers As New InkRecognizers
    Dim theRecognizer As IInkRecognizer
    Set theRecognizer = theRecognizers.GetDefaultRecognizer
    Set theRecognizerContext = theRecognizer.CreateRecognizerContext
    'Initialize the recognizer's strokes
    'and assign them to the RecognizerContext
    Set theStrokes = theInkCollector.Ink.Strokes
    Set theRecognizerContext.Strokes = theStrokes
End Sub

Private Sub theRecognizerContext_Recognition( _
ByVal RecognizedString As String, _
ByVal CustomData As Variant, _
ByVal RecognitionStatus As MSINKAUTLib.InkRecognitionStatus)
        'Update the text box with the top result
        Text1.Text = RecognizedString
End Sub

Private Sub theInkCollector_Stroke( _
ByVal Cursor As MSINKAUTLib.IInkCursor, _
ByVal Stroke As MSINKAUTLib.IInkStrokeDisp, _
Cancel As Boolean)
    'When a new stroke is collected, add it to
    'the RecognizerContext's strokes collection
    theStrokes.Add Stroke
    'Tell the RecognizerContext to recognize
    theRecognizerContext.BackgroundRecognize
    isRecognizingInBackground = True
End Sub

Applies To