Click here to Skip to main content
15,892,293 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
I want to write larger (50mb)bytes to file for download log purpose in my application. I am getting out of memory exception some time. To avoid Out of memory exception i googled and find the below code.

C#
using (StringReader file = new StringReader(result))
               {
                   var line = file.ReadLine();
                   while (line != null)
                   {
                       if (cancelLog)
                       {
                           GC.Collect();
                           return;
                       }
                       File.AppendAllText(fileName, line + Environment.NewLine, new UTF8Encoding());
                       line = file.ReadLine();
                   }
               }


But it takes long time to write the file. Can anyone please tell me the proper way to avoid out of memory exception in larger file situation.

Thanks in advance.
Posted

1 solution

 
Share this answer
 

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