Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

VS 2010 Lambda Expression, Locking, Queuing

$
0
0
I am trying to read in a log file based on changes made to the file. I have a filesystemWatcher looking at the directory for changes, upon changes I run a procedure that checks if the log file was changed. If so I then read in the file, but it is locked because it's in use by another process. I need to queue it so it tries to read again when it's freed by the other application. I need to be efficient when reading the log file for specific keywords. I then need to pull the next few characters after the keywords are found. I am trying to do this so that it is quick enough to keep up with the program writing to the log file.

Here is what I got and it's failing.

vbNET Code:
  1. Public Sub StartInitialization()
  2. fLogWatch = New FileSystemWatcher
  3.  
  4.         With fLogWatch
  5.             .BeginInit()
  6.             .Path = _fLogPath
  7.             .IncludeSubdirectories = False
  8.             .EnableRaisingEvents = True
  9.             .EndInit()
  10.             _serviceStatus.currentState = Fix(State.SERVICE_RUNNING)
  11.             SetServiceStatus(handle, _serviceStatus)
  12.         End With
  13.  
  14. AddHandler fLogWatch.Changed, New FileSystemEventHandler(AddressOf Log_Changed)
  15.  
  16. End Sub
  17.  
  18.  
  19. Private Sub Log_Changed(ByVal obj As Object, ByVal e As FileSystemEventArgs)
  20.         Dim strToFind As String = "CheckForAttachments  Attachment Count:"
  21.         Dim midStrToFind As Integer = 0
  22.         Dim resultStrToFind As String
  23.  
  24.         If e.FullPath = "C:\Users\xxxx\Documents\Sperry Software\SperrySoftwareLog.txt" Then
  25.             Dim llist = File.ReadAllLines(e.FullPath).[Select](Function(line) line.Split(": "))
  26.  
  27.  
  28.  
  29.             For Each l In llist
  30.                 Console.WriteLine(l.ToString)
  31.             Next
  32.         End If
  33.  
  34.         'Using readLog As New StreamReader(e.FullPath, System.Text.Encoding.Default, False, 4096)
  35.  
  36.         '    Dim input = readLog.ReadToEnd
  37.         '    If input.Contains("CheckForAttachments Attachment Count:") Then
  38.         '        resultStrToFind= Mid(strToFind,input.
  39.         '    End If
  40.  
  41.         'End Using
  42.  
  43.     End Sub

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>