G
Guest
I created a Windows Service (written in VB.NET) that uses a FileSystemWatcher
to monitor a directory for file creation. When files with a certain
extension are created in the directory, the file is opened and read
(something is done with the contents). Then the file is moved to a backup
directory. Everything works fine when the coe runs as a standard Windows app,
but when I run the code as a Windows Service, I get the following error when
I try to open the file:
The process cannot access the file "C:\Data\tests.txt" because it is being
used by another process.
Here is the VB code (FileSystemWatcher Created Event happens as it should):
....
Dim objFile As New FileInfo(fullPath)
Dim strContents As String
Dim objStream As StreamReader
' *** Error Happens on the next line ***
objStream = objFile.OpenText()
strContents = objStream.ReadToEnd()
' Close the stream
objStream.Close()
Thanks for any suggections.
to monitor a directory for file creation. When files with a certain
extension are created in the directory, the file is opened and read
(something is done with the contents). Then the file is moved to a backup
directory. Everything works fine when the coe runs as a standard Windows app,
but when I run the code as a Windows Service, I get the following error when
I try to open the file:
The process cannot access the file "C:\Data\tests.txt" because it is being
used by another process.
Here is the VB code (FileSystemWatcher Created Event happens as it should):
....
Dim objFile As New FileInfo(fullPath)
Dim strContents As String
Dim objStream As StreamReader
' *** Error Happens on the next line ***
objStream = objFile.OpenText()
strContents = objStream.ReadToEnd()
' Close the stream
objStream.Close()
Thanks for any suggections.