المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : File being used by another process? I don't think so!



C# Programming
05-02-2011, 07:11 AM
Hi,
I am trying to code an application which reads some data from a NetworkStream, saves it into a buffer byte array and then appending it to a file.

Here is the part I am writing the data from the byte array into the file:
FileStream fs = new FileStream(last_save_********, FileMode.Append, FileAccess.Write); fs.Write(message, 8, bytesRead - 8); fs.Close(); fs.Dispose();
Everything seems to function fine. I can write the data from NetworkStream to the buffer byte array and then into the file for a while. However, after some time, I get the following error:
The process cannot access the file 'C:\Users\Main\Desktop\test.bin' because it is being used by another process.

I am quite sure that no other process is using the file and that I close the handle each and every time. What do you think the problem is?

Regards,
Can