Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0 WinForm
I am developing software with OCR function for a client. I am using Visual studio 2012. Everything works fine except the part where OCR functionality is called. Winform is frozen for 10 or 15 sec and after that everything is OK again (I can move my mouse and click on form buttons again. Is there a way to make OCR function work separate from main form ?
Posted 15-Apr-13 6:01am
Comments
ThePhantomUpvoter at 15-Apr-13 11:02am
   
Yes it's called "threading"
Sergey Alexandrovich Kryukov at 15-Apr-13 11:13am
   
That's right :-). I answered in detail, please see.
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

What do you expect? You make your UI thread busy with lengthy operation, why could you expect some UI activity? By miracle? Smile | :)
 
And this is not related to a form. Why do you think that forms work independently?
 
You need to execute all blocking or lengthy operations in a separate thread, other then UI, to keep UI responsive. The only problem is: you cannot call anything related to UI from non-UI thread. Instead, you need to use the method Invoke or BeginInvoke of System.Windows.Threading.Dispatcher (for both Forms or WPF) or System.Windows.Forms.Control (Forms only).
 
You will find detailed explanation of how it works and code samples in my past answers:
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].
 
See also more references on threading:
How to get a keydown event to operate on a different thread in vb.net[^],
Control events not firing after enable disable + multithreading[^].
 
—SA
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You are doing everything in the main thread most proably and that’s why GUI freezes. You need to start a new background thread for the processing you want to do.
 
You can find more information here:
http://msdn.microsoft.com/en-us/library/system.threading.parameterizedthreadstart.aspx[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 200
1 George Jonsson 175
2 Kornfeld Eliyahu Peter 169
3 PIEBALDconsult 110
4 Richard MacCutchan 85
0 OriginalGriff 6,080
1 DamithSL 4,648
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,624
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 15 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100