|
-
September 15th, 2009, 01:11 PM
#4
Re: File.Delete File.Move Only Works in Debug
The problem is simply that the TextReader and TestWriter objects haven't been disposed.
Just wrap them in a couple of using blocks.
Code:
using( TextReader tr = new StreamReader("List.txt") )
{
using( TextWriter tw = new StreamWriter("List2.txt") )
{
//Guts
}
}
File.Delete("List.txt");
File.Move("List2.txt", "List.txt");
In a general sense, in my opinion, there aren't any 'timing' issues in Windows. Instead there are [lack of] synchronization issues.
In other words, if you view these sorts of problems as 'timing' related, you'll always have trouble because things happen differently in different environments. Instead view it as a synchronization issue and figure out what you need to do to synchronize the operations properly. In this case, it's just adding the using block so you know the file handles are released after leaving the using block scope (and before the Delete and Move operations are run).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|