Re: Display contents of text file in the Browser

From: Kevin Spencer (kevin_at_takempis.com)
Date: 03/25/04


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?


Relevant Pages

  • Re: Converting numbers into words
    ... > Can anyone point me at a function that takes a numeric parameter and ... > a string containing the number in words? ... I'm writing an app that ...
    (microsoft.public.vb.general.discussion)
  • Converting numbers into words
    ... Can anyone point me at a function that takes a numeric parameter and returns ... a string containing the number in words? ... I'm writing an app that prints ...
    (microsoft.public.vb.general.discussion)
  • Re: display strings and numbers
    ... > I'm writing my first m files, and I still have some problem with the ... > How can I display the results of an operation, with a string that mix ... Prev by Date: ...
    (comp.soft-sys.matlab)
  • Re: =?UTF-8?B?bGVuZ3RoIG9mIHZhcmlhYmxl?=
    ... I am writing a short app that will collect some information and produce a text file based on that information. ... strings are immutable, the various methods on string don't modify the existing string but return a new, modified one) ... Hans Kesting ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: string recognize and led
    ... I'm writing a code to recognize two strings of 0s and 1s base on a ... Moore machine. ... when the appropriate string is recongnized the number ... Led_Display <= Whatever you need to display a '5' ...
    (comp.lang.vhdl)