InkEdit recognize in WinForms

In our recent project we used InkEdit control, and we did it in WinForms. Doing that found there are some tricky things there.

Here is the problem. Let’s say I need to close modal window with this control. Before doing that I would like to call Recognize to get latest data from control. However, the procedure is not synchronized. It works this way.

Thread A: call to method recognize returns immediately.
Thread B: event Recognition is raised, if there are data to recognize.

So, I created EventWaitHandle object in thread A and set signal in thread B. Then I waited for WaitHanlde for up to 1 second. If I got event signal – there was text to get from control and if I didn’t, there were just nothing new to recognize.

However, it didn’t work. And the reason it didn’t work was that for data to get into control, it had to get some time in main thread, which is thread A. So, I just got kind of deadlock here.

Unfortunately, I couldn’t resolve the problem without call to Application.DoEvents(), which I always try to avoid.

Final Result.

Thread A:
Recognize with WaitHandle
Wait for WaitHandle signal.
If signal received – call ApplicationDoEvents.
Get value from control.

Thread B:
Event handler for Recognition set signal for EventWaitHandle.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>