I have written a class that stores user options throughout the program. (Color preferences, startup windows, etc.) When the program initializes, a FileStream object is used to open then file then a binary formatter is used to deserialize the stream. The FileStream is then closed.
The problem is that when the program closes and the FileStream object trys to open the file to save the updated user options. A file exception is sometimes threw: "Cannot access file because it is being used by another proccess". Whats so annoying about the error is that it only happens SOMETIMES! A debugging nightmare! I assume that the object handle is not being released somewhere in memory. Can anybody give me any pointers on overcoming this problem?
Loading
JordiPosted Jul 13, 2007, 11:36 AM
Perhaps you are trying to access a file being used already.
If you programatically read a CSV file that is open and you already had an Excel spreadsheet open of that CSV file, you'd get the results you report.
Try closing all files down first.
AlanPosted Jul 6, 2007, 3:28 PM
retry:
try
{
// code to open filestream
}
catch
{
goto retry;
}