By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,746 Members | 1,280 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,746 IT Pros & Developers. It's quick & easy.

Why is process locking directroy?

P: n/a
I have developed a Windows Service application that uses a file watcher to
watch for new files being dumped into an directroy. As soon as it sees a
new file, it moves it to a different directory for it to be processed. In
the processing I use a streamreader to pull each line for parsing into a
database.

The problem, is that the first file after the service is started works as
expected, but any subsequent files that is put in the directory cannot be
moved to the processing directory. I get the following error message:

"The process cannot access the file "\\Server\Share\Directory\newfile.txt"
because it is being used by another process."

After using File.Move(OrigFile, NewFile) I call the processing class which
uses a streamreader that I close and set to nothing after completion. I
then set the processing class to nothing.

Any suggestions or ideas??

TIA,
Jim

Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies

P: n/a
Hi Jim,

How did you dump the file into the dir?
Can you show a small reproduce sample?
Also you may try to use the tool below to see which process locked file and
then check that process.
Handle
http://www.sysinternals.com/utilities/handle.html

e.g.
handle test.txt

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #2

P: n/a
I did some more testing and discovered that if I wait a while an additional
file will work fine. At this point it is good enough as this is going to be
a daily upload to an FTP folder. But for some reason, it appears that the
Stream Reader is locking the directory for a period of time...

Jim

""Peter Huang" [MSFT]" <v-******@online.microsoft.com> wrote in message
news:pa*************@TK2MSFTNGXA01.phx.gbl...
Hi Jim,

How did you dump the file into the dir?
Can you show a small reproduce sample?
Also you may try to use the tool below to see which process locked file
and
then check that process.
Handle
http://www.sysinternals.com/utilities/handle.html

e.g.
handle test.txt

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no
rights.


Nov 21 '05 #3

P: n/a
Hi

I guess that may be the cache mechanism.
You may try to call Close on the StreamReader and then set it to Nothing,
and then call the below to force the GC to collect.
GC.Collect()
GC.WaitForPendingFinalizers()

Also you may try to use the File class directory to see if that have any
help.
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemiofilememberstopic.asp
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.