473,503 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why is process locking directroy?

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
3 929
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
6484
by: Joshua Beall | last post by:
Hi All, I am doing some work where I want to do locking, and prevent scripts from running in parallel. I see that I could use the semaphore mechanism, but I'd like for my code to be portable,...
12
2866
by: serge calderara | last post by:
Dear all, I have an application which is suppose to start another executable process. As soon as that process is running, I need to retrive its handle. The problem of the particular process I am...
5
4289
by: Shuaib | last post by:
I wonder if anybody could shed some light on a problem I am encountering. I have written a program in C that runs on Solaris 2.8. At busy times of the day there may be multiple instances of it...
4
13222
by: Earth Worm Jim | last post by:
I am using VS.Net 2003 on Windows 2003 Server (standard edition) and I am getting "The process cannot access the file because it is being used by another process" on DLL's in a VS.Net solution. ...
1
1673
by: Henry Chen | last post by:
We have a web server that runs on Windows 2000/IIS 5. We have multiple site of web application on the web server. Each site has it own assembly versions of ASP.Net application. They are all...
1
19847
by: ABCL | last post by:
Hi All, I am working on the situation where 2 different Process/Application(.net) tries to open file at the same time....Or one process is updating the file and another process tries to access...
4
9596
by: Paddy | last post by:
We have a recurring problem where a (long-running) service throws an exception while trying to access a file. The problem is that this is very rare (happens once every week and without warning) but...
13
11111
by: George | last post by:
Hi, I am re-writing part of my application using C#. This application starts another process which execute a "legacy" program. This legacy program writes to a log file and before it ends, it...
7
8814
by: atlaste | last post by:
Hi, I have two different things I'd like to discuss here. Both are about cross-process synchronization of shared resources. The resources that are shared are: (1) an object writing to a file and...
0
7192
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7064
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6974
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4665
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3158
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3147
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1492
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.