This documentation is archived and is not being maintained.

RecognizerContextRecognitionEventHandler Delegate

Represents the method that handles the Recognition event of a RecognizerContext object.

Namespace:  Microsoft.Ink
Assembly:  Microsoft.Ink (in Microsoft.Ink.dll)

public delegate void RecognizerContextRecognitionEventHandler(
	Object sender,
	RecognizerContextRecognitionEventArgs e


Type: System.Object

The source RecognizerContext object of this event.

Type: Microsoft.Ink.RecognizerContextRecognitionEventArgs

The RecognizerContextRecognitionEventArgs object that contains the event data.

The Recognition event occurs when the RecognizerContext object has generated results from the BackgroundRecognize method.

When you create a RecognizerContextRecognitionEventHandler delegate, you identify the method that handles the event. To associate the event with your event handler, add an instance of the delegate to the event. The event handler is called whenever the event occurs, unless you remove the delegate.


If you try to gain access to the original RecognizerContext object from the RecognizerContextRecognitionEventHandler delegate, the behavior is unpredictable. Do not attempt to do this.

In this example, each stroke made in an InkOverlay object is automatically recognized and the recognition result displayed.

During application startup, the RecognizerContext object is instantiated, and event handlers are assigned.

// create a new RecognizerContext object 
// the object's Strokes property is initialized to null
mRecognizerContext = new RecognizerContext();
// assign the Strokes property by creating a fresh Strokes collection 
mRecognizerContext.Strokes = mInkOverlay.Ink.CreateStrokes();
// subscribe to the Strokes event. It is during this event 
// that we can add strokes to the RecognizerContext
mInkOverlay.Stroke += new InkCollectorStrokeEventHandler(mInkOverlay_Stroke2);
// subscribe to the the Recognition event.  
// This event is fired when background recognition is complete,  
// and recognition results (without alternates) are available
mRecognizerContext.Recognition += 
    new RecognizerContextRecognitionEventHandler(mRecognizerContext_Recognition);

When the Stroke event fires (in response to the user completing a stroke), the newly created stroke is added to the Strokes collection of the RecognizerContext object, and the BackgroundRecognize method is called.

private void mInkOverlay_Stroke2(object sender, InkCollectorStrokeEventArgs e)
    // in case background recognition is still occurring, stop it
    // add the stroke, and start recognition

When background recognition is complete, the Recognition event fires. During handling of this event, the results of the recognition are placed in a list box.

// event fires when recognition results (without alternates) are ready 
private void mRecognizerContext_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() 
            new RecognizerContextRecognitionEventHandler(mRecognizerContext_Recognition), 
            new object[] { sender, e }
    if (RecognitionStatus.NoError == e.RecognitionStatus)

Windows 7, Windows Vista, Windows Server 2008 R2, Windows Server 2008

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.0