raulbolanos
April 20th, 2009, 03:34 AM
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.
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.
Here is an example code, tell me if the IO functions are wrong, if should I use other functions.
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.