Helo.
Thanks for all answers!
Personally, I would run an out-of-process serviced component that you
only allow one instance of (by setting it to run in a pool, the max and min
size of the pool being one). However, you can also use remoting to have one
instance on a machine, and then access the remote object which accesses the
file.
Thanks, servised component shoud be OK....remoting? isn't it to slow while
communicating on localhost?
I think that you might get better results though if you allow multiple
instances of the class to be created, and place the appropriate locks on the
file. Your class isn't the only thing that can potentially open the file,
so placing locks on the file level would be a better way to go, IMO.
Ok, it seems to be a good solution...but what this sample doesn't work (and
does not throw any exception?)
using System;
using System.IO;
using System.Text;
class Test
{
public static void Main()
{
string path = "MyTest.txt";
Byte[] info1 = new UTF8Encoding(true).GetBytes("This is some text in
the file. 1\r\n");
Byte[] info2 = new UTF8Encoding(true).GetBytes("This is some text in
the file. 2\r\n");
FileStream fs1 = File.Open(path, FileMode.Append, FileAccess.Write,
FileShare.Write);
fs1.Write(info1, 0, info1.Length);
Console.WriteLine("zapisalem");
FileStream fs2 = File.Open(path, FileMode.Append, FileAccess.Write,
FileShare.Write);
fs1.Write(info1, 0, info1.Length);
Console.WriteLine("zapisalem");
fs2.Write(info2, 0, info2.Length);
Console.WriteLine("zapisalem");
fs2.Write(info2, 0, info2.Length);
Console.WriteLine("zapisalem");
fs2.Close();
fs1.Close();
}
}
Pawel Janik