Click here to Skip to main content
15,914,163 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Anyone please help me.....Procedure not shown in my report. Pin
andyharman20-Feb-07 0:34
professionalandyharman20-Feb-07 0:34 
QuestionEmail Host Pin
The ANZAC19-Feb-07 18:47
The ANZAC19-Feb-07 18:47 
AnswerRe: Email Host Pin
Christian Graus19-Feb-07 19:07
protectorChristian Graus19-Feb-07 19:07 
GeneralRe: Email Host Pin
The ANZAC19-Feb-07 19:30
The ANZAC19-Feb-07 19:30 
GeneralRe: Email Host Pin
The ANZAC19-Feb-07 20:03
The ANZAC19-Feb-07 20:03 
QuestionDatagrid in vb.net Pin
Pertik Garg19-Feb-07 18:16
Pertik Garg19-Feb-07 18:16 
AnswerRe: Datagrid in vb.net Pin
GoodID19-Feb-07 21:10
GoodID19-Feb-07 21:10 
AnswerRe: Datagrid in vb.net Pin
NanaAM20-Feb-07 0:54
NanaAM20-Feb-07 0:54 
QuestionReset an integer Pin
rudemusik19-Feb-07 15:38
rudemusik19-Feb-07 15:38 
AnswerRe: Reset an integer Pin
Christian Graus19-Feb-07 19:10
protectorChristian Graus19-Feb-07 19:10 
GeneralRe: Reset an integer Pin
rudemusik20-Feb-07 13:20
rudemusik20-Feb-07 13:20 
GeneralRe: Reset an integer Pin
TwoFaced20-Feb-07 18:32
TwoFaced20-Feb-07 18:32 
GeneralRe: Reset an integer Pin
rudemusik21-Feb-07 5:31
rudemusik21-Feb-07 5:31 
AnswerRe: Reset an integer Pin
lucky.prem19-Feb-07 20:03
lucky.prem19-Feb-07 20:03 
GeneralRe: Reset an integer Pin
rudemusik20-Feb-07 13:28
rudemusik20-Feb-07 13:28 
QuestionRead last line of logfile and close file immediately Pin
bodobe19-Feb-07 10:10
bodobe19-Feb-07 10:10 
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 

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.