I have application which write to file every minute. Sometimes (every 10 minutes +-) I get error
There is not enough space on the disk
My app is a Windows Forms application. I read a lot articles on google but it didn't give me any result how to fix it.
Exception:
Exception thrown: 'System.IO.IOException' in mscorlib.dll
My code:
try
{
FileStream stream = new FileStream(file, FileMode.CreateNew);
FileStream stream2 = new FileStream(file2, FileMode.CreateNew);
BinaryFormatter writer = new BinaryFormatter();
writer.Serialize(stream, GetProducts().Take(80000).ToList());
writer.Serialize(stream2, GetProducts().Skip(80000).ToList());
stream.Flush();
stream.Close();
stream2.Flush();
stream2.Close();
}
catch(Exception ex)
{
Debug.WriteLine($"FAIL to write: {i} - {ex.Message}");
}
My total free space on disk is 74GB. Before last run of program I did defragmentation.
How am I supposed to get rid of this error?
Thanks
EDIT: Screen available here
EDIT2: Stacktrace
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.WriteCore(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.FileStream.FlushWrite(Boolean calledFromFinalizer)
at System.IO.FileStream.Dispose(Boolean disposing)
at System.IO.FileStream.Finalize()