470,632 Members | 2,454 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,632 developers. It's quick & easy.

The process cannot access the file ...

Hello , I have windows service which do listening to specified directory
using FileSystemWatcher , on Created Event and Get all the files in the
directory using Directory.GetFiles function then foreach file in the files
list and passed the file path to a function to read its content then process
it then move it to another directory
am reading each file content using StreamReader...ReadToEnd function, all
process working fine , That when 50 files are copied simultanously there are
no error , but when more than this like 60 or 80 or more a error messages
logged to error log like following

Error in Message Object-> MessageObject.SendMessage() (C:\queue\
26e54303de8e431c81f9e1004c427590.msg) >>The process cannot access the file
"C:\queue\ 26e54303de8e431c81f9e1004c427590.msg" because it is being used by
another process.

How Can I effectively avoid this problem?????

Nov 17 '05 #1
2 7565
You need to post your code I think. This may get you a better chance of a
solution.

--
Terry Burns

http://TrainingOn.net


"Raed Sawalha" <Ra*********@discussions.microsoft.com> wrote in message
news:EC**********************************@microsof t.com...
Hello , I have windows service which do listening to specified directory
using FileSystemWatcher , on Created Event and Get all the files in the
directory using Directory.GetFiles function then foreach file in the files
list and passed the file path to a function to read its content then
process
it then move it to another directory
am reading each file content using StreamReader...ReadToEnd function, all
process working fine , That when 50 files are copied simultanously there
are
no error , but when more than this like 60 or 80 or more a error messages
logged to error log like following

Error in Message Object-> MessageObject.SendMessage() (C:\queue\
26e54303de8e431c81f9e1004c427590.msg) >>The process cannot access the file
"C:\queue\ 26e54303de8e431c81f9e1004c427590.msg" because it is being used
by
another process.

How Can I effectively avoid this problem?????

Nov 17 '05 #2
Hello Raed,

Your message is difficult to read.

Here's what I think you said. Please correct me (using sentences with
periods, please).

You use FileSystemWatcher to be informed of an event.
You then scan the directory and files tree getting all files.
You open the file, process it, and move it to another directory.

When you find 50 files, you do not get an error.
When you find 60-80 files, you get errors that some of the files are being
written by another process.

Sounds like the process that is writing the files isn't done with them yet.

Note that FileSystemWatcher will return an event when a single file is
modified. You will get the name of the file. You appear to be ignoring the
name of the file and you are searching the directory for other files. This
means that you will get files that are not finished being written yet.

Why not just trust the FileSystemWatcher to send you the name of each file?
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Raed Sawalha" <Ra*********@discussions.microsoft.com> wrote in message
news:EC**********************************@microsof t.com...
Hello , I have windows service which do listening to specified directory
using FileSystemWatcher , on Created Event and Get all the files in the
directory using Directory.GetFiles function then foreach file in the files
list and passed the file path to a function to read its content then
process
it then move it to another directory
am reading each file content using StreamReader...ReadToEnd function, all
process working fine , That when 50 files are copied simultanously there
are
no error , but when more than this like 60 or 80 or more a error messages
logged to error log like following

Error in Message Object-> MessageObject.SendMessage() (C:\queue\
26e54303de8e431c81f9e1004c427590.msg) >>The process cannot access the file
"C:\queue\ 26e54303de8e431c81f9e1004c427590.msg" because it is being used
by
another process.

How Can I effectively avoid this problem?????

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by =?Utf-8?B?VkIgSm9ubmll?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.