I am using a serialized object to maintain state and to back up a database
incase the SQL server isn't available. I would like to delete the
database.state file I create programmatically when I reinitialize it. I do
this with the File.Delete(String path); static method. I am getting the
following error, even if I close the console application and restart it:
The process cannot access the file
"C:\RAFT.NET\Service\State\Database\Database.state" because it is being used by
another process. System.IO.IOException: The process cannot access the file
"C:\RAFT.NET\Service\State\Database\Database.state" because it is being used by
another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.File.Delete(String path)
at com.TheHartford.HTSC.RAFT.FileWatcher.FileWatcher.loadDatabaseItems() in
c:\raft\filewatcher\code\filewatcher.cs:line 123 mscorlib
This is my serialization method, in which I try to delete the file if it is
present.
public void DoSerialize(String Path, object o) {
lock (syncRoot2) {
try {
DoMessaging("FW000016", Path, DateTime.Now);
FileStream myFileStream = null;
if (!myInstance.DoesFileExist(Path))
myFileStream = File.Create(Path);
else {
if
(Path.Equals(_MyApplicationInitializedData.DatabaseStatePath)) {
File.Delete(Path);
myFileStream = File.Create(Path);
}
else
myFileStream = File.OpenWrite(Path);
}
BinaryFormatter serializer = new BinaryFormatter();
serializer.Serialize(myFileStream, o);
serializer = null;
myFileStream.Close();
myFileStream = null;
DoGarbageCollection();
}
catch (Exception ex) {}
}
}
My question is how can I force a delete or, how can I make sure the file is not
being used by someone. I am positive that at start up, my application is not
using this file; I don't know why it thinks it is being used.
Travis D. Falls | Consultant RAFT.Net IT | 860.547.4070 | [EMAIL PROTECTED]
*************************************************************************
This communication, including attachments, is
for the exclusive use of addressee and may contain proprietary,
confidential and/or privileged information. If you are not the intended
recipient, any use, copying, disclosure, dissemination or distribution is
strictly prohibited. If you are not the intended recipient, please notify
the sender immediately by return e-mail, delete this communication and
destroy all copies.
*************************************************************************
[Non-text portions of this message have been removed]
------------------------ Yahoo! Groups Sponsor --------------------~-->
Fair play? Video games influencing politics. Click and talk back!
http://us.click.yahoo.com/T8sf5C/tzNLAA/TtwFAA/saFolB/TM
--------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/