c# - Advanced Reading of File -


I am sure all of us are familiar and may use excessive code in books, online, etc. in reading. We do. Using a C # as a simple file ...

  stringbuilder fiContents = new StringBuilder (); (StreamReader fi = new stream reader (@ "C: Using \ a_file.txt")) (while (! Fi.EndOfStream) {fiContents.Append (fi.ReadLine);}}   

or maybe something as small ...

  using (StreamReader fi = new StreamReader (@ "C: \ a_file.txt")) fiContents.Append (fi .ReadToEnd ());   

now we are super Saiyn for a moment and really fancy stuff such as a BackgroundWorker which we have a loading image (Which I will use), a process countdown clock or Provide speed barara .

  public void Reedfail (string filename) {Prishtbhumivrkkar procFile = new Prishtbhumivrkr (); // progress 1: If we want to show the progress we are following property // procFile.WorkerReportsProgress = true need enabling; profile.DoWork + = new DoWorkEventHandler ((object obj, DoWorkEventArgs EV) = & gt; {StringBuilder fiContents = new StringBuilder (); (StreamReader Fi = New StreamReader (file name)) {while (fi.EndOfStream) {// Progress! . 2:; fiContents.Append (fi progress report handler associated with the (down) // procFile.ReportProgress ((int) (fi.BaseStream.Length / fi.BaseStream.Position) / will be dealt by 100) .ReadLine);}} ev.Result = fiContents;} / * progress 3: down to update the progress of the handler file it will take care of the action procFile.ProgressChanged + = new ProgressChangedEventHandler ((object obj, ProgressChangedEventArgs EV). = & gt; {// progress 4 :. with some updating this a ProgressBar such as price, what // ....} * / procFile.RunWorkerCompleted + = new RunWorkerCompletedEventHandler ((object obj, RunWorkerCompleted EventArgs EV) = & gt; keeping some (Eve. Result), each with {/ / results, it is a Stringbiilder and Eve. As a result of an object. Stringbu ilder result = ev.Result StringBuilder; // ....}}   

++++++++++++++++++++

real-time questions. .. above was a warm up and to show the understanding of the present level, so I do not face them as a future answer.

I used the previous code example (i.e. BackgroundWorker < using / code> Sector) have been and I'm dump the contents of which are read at RichTextBox . The ordinary stuff actually

The problem I am experiencing is processing large files (eg ~ 222 MB) The case only takes one .txt, reading it, reading it StringBuilder is created in RichTextBox . Can not load this file, I get a OutOfMemoryException A path around this, which takes a considerable amount of time (and still does not load the file) moves through the string and each letter ( char ) of the file StringBuilder

I have always used the most basic and straightforward means of reading files (such as the examples given above), but does anyone have any guidance to improve it? Extra Large Files Processing Methods? e.t.c.

Even as a piece of discussion, I welcome your views.

+++++++++++++++++

Edit 1 (@TaW): Exceptions when < code> was thrown trying to put the string in RichTextBox ...

  FileProcessing.RunWorkerCompleted + = new RunWorkerCompletedEventArgs ((object obj, RunWorkerCompletedEventArgs e) = & gt; {// 'code' in question ... Code.Text = "" RichTextBox, if (e.Result StringBuilder) {Code.Text = (e.Result as StringBuilder) .ToString (S);}}  

Do you have any restrictions, It is necessary to use your content As a control for displaying ri? It is designed to control virtualized and you will cause the display (and memory anticipates error).

showed the greatest document of a family in There are different controls depending on your needs (flowing through the default, page or scrolling). Besides, you get search, printing, zooming and some other features Rte which are often useful for viewing large documents.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -