Click here to Skip to main content
16,012,508 members
Home / Discussions / C#
   

C#

 
AnswerRe: TreeView Pin
Jimmanuel12-Feb-09 3:07
Jimmanuel12-Feb-09 3:07 
GeneralRe: TreeView Pin
Udayaraju15-Feb-09 4:53
Udayaraju15-Feb-09 4:53 
GeneralRe: TreeView Pin
Udayaraju15-Feb-09 5:09
Udayaraju15-Feb-09 5:09 
GeneralRe: TreeView Pin
Udayaraju15-Feb-09 5:20
Udayaraju15-Feb-09 5:20 
QuestionFile Processing Error Pin
MumbleB11-Feb-09 19:53
MumbleB11-Feb-09 19:53 
AnswerRe: File Processing Error Pin
ABitSmart11-Feb-09 21:04
ABitSmart11-Feb-09 21:04 
GeneralRe: File Processing Error Pin
MumbleB11-Feb-09 21:08
MumbleB11-Feb-09 21:08 
AnswerRe: File Processing Error Pin
Eddy Vluggen11-Feb-09 21:25
professionalEddy Vluggen11-Feb-09 21:25 
Kwagga wrote:
I can't change this to ReadLine.

Why not?

Most commands are blocking; i.e., execution is halted until the instruction is completed. ReadToEnd() reads the *entire* file, before moving on to the next instruction. This will take a lot of time if you got a large file - in some cases longer than a minute. If Windows' doesn't get any messages from your application, it will assume that your either a dead application, or an application that should be dead. The so much feared,
"XXX has become unresponsive".

Instructions should do their thing fast, and move on. Longer-running processes must give a signal to Windows, just to prove that the application is still actually doing processing, instead of just "hanging dead in some loop".

Windows wants to kill your app, because you didn't phone home from work. So, the right way would be to make that call, whilst working. Now, the problem with ReadToEnd is that you can't stop it and tell it to call Windows.. So, that's something you'll have to build yourself.
string holdLine = string.Empty;
string output = string.Empty;
while (!sr.EndOfStream)
{
    //Reason: Blocks on large files.
    //START REPLACE string holdLine = sr.ReadToEnd();
    holdLine += sr.ReadLine();
    Application.DoEvents();
    //END REPLACE string holdLine = sr.ReadToEnd();

    if (String.IsNullOrEmpty(holdLine))
        continue;

    output += Regex.Replace(holdLine, "\r(?!\n)", " ");
}
sw.WriteLine(output);
sr.Close();


The Streamer now reads all lines as separate lines, does it's work on it,
and appends it to the output-string. The entire outputstring is written to disk when the looping is done.

The above code wasn't tested, but should be enough to get you on track. The Application.DoEvents is there to let Windows' know that your application has not gone James Brown.

You also might want to consider moving this logic to a background-worker. That's going to take more time to research, but once you know how it works, you start re-using the pattern more often. Well worth the investment in time, I daresay Smile | :)

Hope this helps,

I are troll Smile | :)

QuestionOn button click-context menu strip Pin
Udayaraju11-Feb-09 19:47
Udayaraju11-Feb-09 19:47 
AnswerRe: On button click-context menu strip Pin
ABitSmart11-Feb-09 20:08
ABitSmart11-Feb-09 20:08 
AnswerRe: On button click-context menu strip Pin
DaveyM6911-Feb-09 22:56
professionalDaveyM6911-Feb-09 22:56 
GeneralRe: On button click-context menu strip Pin
Udayaraju15-Feb-09 4:54
Udayaraju15-Feb-09 4:54 
GeneralRe: On button click-context menu strip Pin
DaveyM6915-Feb-09 6:33
professionalDaveyM6915-Feb-09 6:33 
Questionc# Pin
aratireddy11-Feb-09 17:14
aratireddy11-Feb-09 17:14 
AnswerRe: c# Pin
ABitSmart11-Feb-09 18:43
ABitSmart11-Feb-09 18:43 
QuestionHow to create and execute of a simple Function with input and output parameters in pl/sql using with c#.net Pin
AnilJayanti11-Feb-09 16:40
AnilJayanti11-Feb-09 16:40 
Questionleading numbers in a text string appearing at end of text in a Rich Text Box. Pin
Willbo_II11-Feb-09 15:15
Willbo_II11-Feb-09 15:15 
GeneralRe: leading numbers in a text string appearing at end of text in a Rich Text Box. Pin
Luc Pattyn11-Feb-09 16:02
sitebuilderLuc Pattyn11-Feb-09 16:02 
QuestionSet license key / product in c# project - installation package. Pin
thecodesource7911-Feb-09 14:55
thecodesource7911-Feb-09 14:55 
AnswerRe: Set license key / product in c# project - installation package. Pin
DJ-Boris12-Feb-09 0:31
DJ-Boris12-Feb-09 0:31 
GeneralRe: Set license key / product in c# project - installation package. Pin
thecodesource7912-Feb-09 13:52
thecodesource7912-Feb-09 13:52 
AnswerRe: Set license key / product in c# project - installation package. Pin
Member 114976512-Dec-09 0:53
Member 114976512-Dec-09 0:53 
QuestionStartup Performance Pin
Wizard_0111-Feb-09 11:00
Wizard_0111-Feb-09 11:00 
QuestionSomething better than Switch Case Pin
Muammar©11-Feb-09 10:12
Muammar©11-Feb-09 10:12 
AnswerRe: Something better than Switch Case Pin
akidan11-Feb-09 10:20
akidan11-Feb-09 10:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.