Click here to Skip to main content
15,882,598 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Read last line of logfile and close file immediately Pin
Marcus J. Smith19-Feb-07 10:14
professionalMarcus J. Smith19-Feb-07 10:14 
GeneralRe: Read last line of logfile and close file immediately Pin
bodobe19-Feb-07 10:23
bodobe19-Feb-07 10:23 
GeneralRe: Read last line of logfile and close file immediately Pin
Marcus J. Smith19-Feb-07 10:29
professionalMarcus J. Smith19-Feb-07 10:29 
GeneralRe: Read last line of logfile and close file immediately Pin
bodobe19-Feb-07 10:40
bodobe19-Feb-07 10:40 
GeneralRe: Read last line of logfile and close file immediately Pin
Marcus J. Smith19-Feb-07 10:47
professionalMarcus J. Smith19-Feb-07 10:47 
AnswerRe: Read last line of logfile and close file immediately Pin
TwoFaced19-Feb-07 13:06
TwoFaced19-Feb-07 13:06 
GeneralRe: Read last line of logfile and close file immediately Pin
bodobe20-Feb-07 20:43
bodobe20-Feb-07 20:43 
GeneralRe: Read last line of logfile and close file immediately Pin
TwoFaced20-Feb-07 21:32
TwoFaced20-Feb-07 21:32 
Your welcome, glad it's working for you. I messed around with the code after I posted it. I also added a try catch block around the IO.File.Open and looped until it was a success with a small wait in between each attempt. Looks like with think a like. Just so you know retrieving the FileInfo object will succeed even if the file doesn't exist. However, if you try to read the file size and the file doesn't exist it will throw an error which would crash your program if you didn't handle it. The info object can actually tell you if the file exists. I check this and leave the procedure if we have no file. This is how I handled it.
Do
    'Get the most up to date information
    info = New IO.FileInfo(file)
    'If file doesn't exist leave
    If Not info.Exists Then Return
    'info.length throws an error if the file doesn't exist, thus the needed line above.
    count = info.Length - index
    Try
        stream = IO.File.Open(file, IO.FileMode.Open, IO.FileAccess.Read)
    Catch ex As Exception
        'Sleep a little and try again later
        Threading.Thread.Sleep(5)
    End Try
Loop While stream Is Nothing
I like your counter to keep track of attempts and respond if there are too many. That's odd that the file isn't ready for reading after the FileSystemWatcher raises the event. I simulated your situation and did a stress test for 3 minutes and it never failed to open the file. Maybe it has to do with the file size. I started from scratch so the file was pretty small.

Just out of curiosity does this logfile ever get cleared? A line a second has to add up.
GeneralRe: Read last line of logfile and close file immediately Pin
Marcus J. Smith23-Feb-07 5:20
professionalMarcus J. Smith23-Feb-07 5:20 
QuestionVB6.0 - Common Dialog "ShowSave" method to get a Folder? Pin
ChemmieBro19-Feb-07 9:55
ChemmieBro19-Feb-07 9:55 
QuestionEncrypted source files Pin
Fernando A. Gomez F.19-Feb-07 8:38
Fernando A. Gomez F.19-Feb-07 8:38 
AnswerRe: Encrypted source files Pin
Dave Kreskowiak19-Feb-07 9:33
mveDave Kreskowiak19-Feb-07 9:33 
GeneralRe: Encrypted source files Pin
Fernando A. Gomez F.19-Feb-07 10:43
Fernando A. Gomez F.19-Feb-07 10:43 
QuestionUseing Serial Port Pin
Max Bayne19-Feb-07 8:13
Max Bayne19-Feb-07 8:13 
AnswerRe: Useing Serial Port Pin
Ankur.Bakliwal19-Feb-07 17:35
Ankur.Bakliwal19-Feb-07 17:35 
Questiondisable groupbox Pin
jds120719-Feb-07 7:56
jds120719-Feb-07 7:56 
AnswerRe: disable groupbox Pin
Marcus J. Smith19-Feb-07 8:19
professionalMarcus J. Smith19-Feb-07 8:19 
AnswerRe: disable groupbox Pin
TwoFaced19-Feb-07 8:23
TwoFaced19-Feb-07 8:23 
QuestionCONVERSION OF VB CODE TO JAVASCRIPT Pin
soadfreak19-Feb-07 7:48
soadfreak19-Feb-07 7:48 
AnswerRe: CONVERSION OF VB CODE TO JAVASCRIPT Pin
Christian Graus19-Feb-07 8:53
protectorChristian Graus19-Feb-07 8:53 
Questionadding new record and saving in VB.NET Pin
7prince19-Feb-07 6:15
7prince19-Feb-07 6:15 
AnswerRe: adding new record and saving in VB.NET Pin
Marcus J. Smith19-Feb-07 8:24
professionalMarcus J. Smith19-Feb-07 8:24 
GeneralRe: adding new record and saving in VB.NET Pin
7prince19-Feb-07 8:46
7prince19-Feb-07 8:46 
AnswerRe: adding new record and saving in VB.NET Pin
Christian Graus19-Feb-07 10:17
protectorChristian Graus19-Feb-07 10:17 
QuestionRetain values in drop down lists between redirects Pin
dasumohan19-Feb-07 5:20
dasumohan19-Feb-07 5:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.