Click here to Skip to main content
16,017,247 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am making a program that requires importing large txt files , i used a txt file 100mb in size and 4 million lines , when i import it and start operating on it , the program makes an application Crash and requires a restart of program , the error name is program has stopped working and problem code is CLR20r3 , i was hopefully you guys guide me through this .
Posted
Updated 30-Jul-11 1:49am
v2
Comments
OriginalGriff 30-Jul-11 7:51am    
How are you read the text file?
Have you tried adding a try...catch block around it and seeing what the exception is?
Member7856259 30-Jul-11 7:57am    
did it and the problem is : Cross-thread operation not valid: Control 'richTextBox1' accessed from a thread other than the thread it was created on. but i dont understand it

Your problem is that controls can only be accessed from the GUI thread. Google Control.Invoke and you will find the nescessary information.

Regards,

MRB
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 2-Aug-11 2:40am    
Correct but there are different methods like that (a bit different for WPF and also BeginInvoke); and it probably needs some explanation. Understanding of help is also not so easy. I voted 5 but added more detail, please see.
--SA
Philippe Mori 2-Aug-11 7:45am    
Another possibility would be to use a BackgroundWorker. Tutorial and MSDN documentation.
More detail on basically correct solution by Manfred:

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
 
Share this answer
 
Uses the debugger to find the problem... and ensure that you break on all exceptions.

For such large files, you might have to properly design your program to handle large files. Depending on what you do with the text, it might take too much memory.

Have you look at the memory usage of your program while importing.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 2-Aug-11 2:41am    
OP explained the problem in comment, so Manfred and I gave more exact solutions, please see.
--SA

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900