I'm having a bit of trouble with a File System Watcher and what looks like Windows Vista. My project has been built on Windows 8.1 as an Administrator and shows no signs of these error messages I get when I try and run this process on Vista.
The below is my FSW that runs at system start up
Sub MFW() If lstMessage.InvokeRequired Then lstMessage.BeginInvoke(New MethodInvoker(AddressOf MFW)) Else watchfolder = New System.IO.FileSystemWatcher() watchfolder.Path = My.Settings.Out watchfolder.Filter = "*.txt" watchfolder.NotifyFilter = NotifyFilters.FileName lstMessage.BeginUpdate() AddHandler watchfolder.Created, AddressOf MessageArray AddHandler watchfolder.Deleted, AddressOf MessageArray lstMessage.EndUpdate() watchfolder.EnableRaisingEvents = True End If End Sub
This then calls the below
Sub MessageArray() If lstMessage.InvokeRequired Then Me.lstMessage.BeginInvoke(New MethodInvoker(AddressOf MessageArray)) Else Try With My.Settings.Out Dim outMail As String = My.Settings.Out lstMessage.Items.Clear() ReDim CISmsg(0 To 0) t = 0 Dim cTxt As New IO.DirectoryInfo(outMail) Dim hello = cTxt.GetFiles("*.txt") ReDim CIStxt(hello.Count - 1) For Each InfoFile In (hello) Dim Lines() As String = File.ReadAllLines(InfoFile.FullName) CIStxt(t) = New Filedetail1() CIStxt(t).mName = Path.GetFileNameWithoutExtension(InfoFile.Name) Dim mline = Lines.Where(Function(x) (x.StartsWith("status="))).SingleOrDefault() If mline IsNot Nothing Then CIStxt(t).mStatus = mline.Split("="c)(1) End If Dim mlines = Lines.Where(Function(x) (x.StartsWith("date="))).SingleOrDefault() If mlines IsNot Nothing Then CIStxt(t).mDate = mlines.Split("="c)(1) End If If CIStxt(t).mStatus = "success" Then lstMessage.Items.Add(CIStxt(t).mName, 0) ElseIf CIStxt(t).mStatus = "fail" Then lstMessage.Items.Add(CIStxt(t).mName, 1) ElseIf CIStxt(t).mStatus = "received" Then lstMessage.Items.Add(CIStxt(t).mName, 2) End If lstRequired.DataSource = Nothing lstRequired.DataBindings.Clear() t = t + 1 Next End With Catch ex As Exception MsgBox(ex.Message) End Try End If End Sub
If i remove the Try, Catch, End Try then I get a system generated error message as opposed to a message box so I'm confident its this code.
The error i'm getting is `The process cannot access the file because its being used by another process'
I'm a bit baffled as, like I say, it doesn't throw this error on Win 8.1
Also here Cross Posted
No comments:
Post a Comment