Strange problem moving files with service

chadrenshaw

New member
Joined
Oct 7, 2008
Messages
1
Programming Experience
1-3
I wrote a service (.NET 2.0) which does a few simple operations, but the one I am having a problem with is when I move files.

Originally I just simpled used the System.IO.File.Move method to execute the file move, but I found that after it was moved successfully, the service still had a lock on the file (ie. I could not move the file myself through the Explorer GUI or any other way because "It is being used by another person or program.") So since I could not figure out why this occurred or how to resolve it through research I basically just wrote my own methods using the FileStream object; one for opening and reading the file and one for creating the new file (ie. where it was to be moved to) and writing it out and closing it. I did it this way because I figured I could at least Close and Dispose of the object after the operation was complete. However, this resulted in the same behavior! The "moved" file was still locked by the service program.

Does anyone know why this could be happening to me? I did not paste any code because there is really nothing wrong with the code, it's got something to do with the fact that it is a service and the program is constantly running. My original method was simply System.IO.File.Move(OldFileName,NewFileName).

Any help is immensely appreciated.

Thanks!

Chad
 
Back
Top