3
Reply

Folder Watch service does not work

my devel

my devel

May 18 2012 4:59 PM
2.4k
Hi,

I've written a service to monitor a folder which is supposed to read a copied file (csv file) extract some information, close it and then move it to the another folder daily bases. file copy from another machine on the same domain. (service and Hot folder and moving destination are on same machine). so the problem is here:
1- whenever file be copy first time it's OK, it read and move it but second time which is next morning day while the service status is Start but it can't read file and show's error that 


" System.IO.IOException:The process cannot access the file 'C:\HotFolder\123.csv'
System.IO.IOException: The process cannot access the file ' C:\HotFolder\123.csv' because it is being used by another process. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options) at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize) at System.IO.StreamReader..ctor(String path) at HotFoder.HotFolder.fileSystemWatcher1_Created(Object sender, FileSystemEventArgs e) in C:\HotFolderFolder\Service1.cs: line 44 "

which line 44 is "StreamReader sr = new StreamReader('C:\HotFolder\123.csv');"

at the same time if I drag and drop same file to Hot Folder it works like a charm.


so if anyone knows what is wrong with that please help me.
Thanks a lot


Answers (3)