Re: Display contents of text file in the Browser
From: Kevin Spencer (kevin_at_takempis.com)
Date: 03/25/04
- Next message: Marina: "Re: why these character substitutions?"
- Previous message: Tracey: "Client-Side Script File Exists?"
- In reply to: Rathtap: "Display contents of text file in the Browser"
- Next in thread: Bill Borg: "Re: Display contents of text file in the Browser"
- Reply: Bill Borg: "Re: Display contents of text file in the Browser"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 25 Mar 2004 15:40:17 -0500
It sounds like your app is attempting to read from the file at the same time
that it is writing to it, which is not possible. I'm guessing that your
asynchronous thread is writing the file, while the Page is continuing to
process and attempting to read the file and display it at the same time. As
the old saying goes, "you can't have it both ways." You can either create an
asynchronous thread to write the file and not attempt to read it at the same
time, or you can write synchronously, in which case your Page class will
wait until the file is writeen and closed (I assume you're closing your
stream in the thread) before it attempts to read it.
Of course, this doesn't solve the problem of waiting for the page to load. I
have one idea. Perhaps you could store the log information in a string in
memory, and return that string to the client, while launching a separate
thread to write the string to a file.
--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"Rathtap" <amcniw@yahoo.com> wrote in message
news:b21a5958.0403251209.21409329@posting.google.com...
> My web app starts a process on a separate thread that is long running
> while I display the user a please wait page. This process writes
> continuously to a log file. It would be a good idea to display its
> contents in the wait page so the user knows something is going on.
> I tried the following in the page load event but I get errors because
> the file is being written to.
> private void Page_Load(object sender, System.EventArgs e)
> {
> Response.Write(@"<META HTTP-EQUIV=Refresh CONTENT=""3; URL=""> ");
> FileInfo dFile = new FileInfo(file);
> long filesize = dFile.Length;
> long start = 0;
> long end = filesize;
> Response.WriteFile(file, start, end);
> Response.End();
> }
> The error reads:
> System.IO.IOException: The process cannot access the file
> "C:\Trace.log" because it is being used by another process.
>
> Any suggestions?
- Next message: Marina: "Re: why these character substitutions?"
- Previous message: Tracey: "Client-Side Script File Exists?"
- In reply to: Rathtap: "Display contents of text file in the Browser"
- Next in thread: Bill Borg: "Re: Display contents of text file in the Browser"
- Reply: Bill Borg: "Re: Display contents of text file in the Browser"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|