"Not Responding" when reading and processing large file

  • Thread starter Thread starter L#
  • Start date Start date
L

L#

I'm working on a win app that reads and processes each line of an ascii file
until the end of the file. Since the file's 1.6 million lines long, after a
while Windows displays the "Not Responding" although the application's
running fine. Is it possible to add anything that'll stop Windows from
displaying that?

Also, how would I be able to always have control of the form in case I want
to abort the process? Once it starts running, I lose control of the form.
I've heard of being able to use threads but I really didn't understand them.

Thank you.

Start a new thread where the processing is done. Your main application
remains responsive that way. Have a look at the following URL for an
example:
http://www.vbcity.com/forums/faq.asp?fid=31&cat=Threading
 
it hungs because the window proc of your appl does not process messages sent
to it.

to fix that create thread which will be reading your large file and make
needed actions.

I advice you to read Richter's "advanced windows" and you will understand
what is "threads"..
 
To do this you really need to spawn the reading process of in another
thread., that way you can stop the thread at anytime.
 
I'm working on a win app that reads and processes each line of an ascii file
until the end of the file. Since the file's 1.6 million lines long, after a
while Windows displays the "Not Responding" although the application's
running fine. Is it possible to add anything that'll stop Windows from
displaying that?

Also, how would I be able to always have control of the form in case I want
to abort the process? Once it starts running, I lose control of the form.
I've heard of being able to use threads but I really didn't understand them.

Thank you.
 
Don't waste the time & complexity of creating and monitoring an additional
thread.

Simply peridically call Application::DoEvents() in your file processing loop.
 
Hi Jimbo,

Thank you for posting in the community!

Based on my understanding, your WinForm application did a large data
processing and the UI does not correspond. Also, you want a way that can
cancel the data processing in your application.

=============================================
To solve the UI corresponding problem, you can just call the
Application.DoEvents static method. If you call DoEvents in your code, your
application can handle the other events. Please refer it in MSDN document.

If you want to get more control over your data processing, I think
Well-designed multi-threading is a good option for you. Usually, you need
to use Main thread, work thead model. Main thread manipulate the UI, while
the work thread processing the data. In multi-threading application, there
are a lot of things you should be careful of. Such as synchronization,
deadlock etc.

I think the article in Philip's reply is a good one for Threading in
WinForm.
Also, you may get information on Fast and Responsive UI with Multiple
Threads at:
http://msdn.microsoft.com/msdnmag/issues/03/02/Multithreading/default.aspx

============================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Have a nice day!!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
I'm working on a win app that reads and processes each line of an ascii file
until the end of the file. Since the file's 1.6 million lines long, after a
while Windows displays the "Not Responding" although the application's
running fine. Is it possible to add anything that'll stop Windows from
displaying that?

Also, how would I be able to always have control of the form in case I want
to abort the process? Once it starts running, I lose control of the form.
I've heard of being able to use threads but I really didn't understand them.

Thank you.


If your program needs to finish processing records before it can do
anything else then the Application.DoEvents is the way to go. Put it in
your loop and then when someone presses the cancel button the event will
fire and you can handle it.

If you program needs to do other things while the records are being
processed, then you need to put the file processing in another thread.

jerry
 
Back
Top