CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    Mar 2009
    Location
    Stuttgart, Germany
    Posts
    56

    Question How to open a file when it is being writted.

    Im constantly saving in one file but it takes a while to finish the process and I want to check sometimes how is everything going in this file, but it does not allow me to take a look because its being used at the moment. I heard, that there is not problem if I open the file with notepad, even thought I still get a message like this; The Process cannot access the file because it is being used by the process.

    Here is an example code, tell me if the IO functions are wrong, if should I use other functions.

    Code:
    using System;
    using System.Threading;
    using System.Collections.Generic;
    using IO = System.IO;
    
    public class Test
    {
        public static void Main()
        {
            int count = 0;
    
            while (true)
            {
                IO.FileStream fs = null;
                IO.BinaryWriter bw = null;
                System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
    
                string path = "C:\\Documents and Settings\\Administrator\\Desktop\\Test.tab";
                fs = IO.File.Create(path);
                bw = new System.IO.BinaryWriter(fs);
    
                Console.WriteLine("{0} second", count);
                Thread.Sleep(1000);
                bw.Write(count);
                bw.Close();
                count++;
            }
        }
    }
    Thank you.
    Last edited by raulbolanos; April 20th, 2009 at 05:01 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured