Hi there 
i've created a program that basically reads a file, checks for the word "error" and then emails sum1 with the "errors". What i need to do now is set the program to read the file every 5 minutes, which ive tried to do but i've messed up somewhere?! when the file has been read, it only sends new errors via email. here is my code:
Imports System
Imports System.IO
Imports System.Collections
Imports System.Web
Public Class Form1
Inherits System.Windows.Forms.Form
Private Shared myTimer As New System.Windows.Forms.Timer
'Private Shared exitFlag As Boolean = False
Private Shared Sub TimerEventProcessor(ByVal myObject As Object, ByVal myEventArgs As EventArgs)
myTimer.Stop()
Dim LineNo As String
Dim CurrentLineNo As New Integer
If GetSetting("OrEM", "Settings", "LineNo"
= "" Then
SaveSetting("OrEM", "Settings", "LineNo", "1"
End If
LineNo = Val(GetSetting("OrEM", "Settings", "LineNo"
)
Dim objReader As New StreamReader("c:\ProjectSearch\sx3liveALRT.LOG"
Dim sLine As String = ""
Dim arrText As New ArrayList
Do
sLine = objReader.ReadLine() : CurrentLineNo = CurrentLineNo + 1
If CurrentLineNo >= LineNo Then
If InStr(UCase(sLine), "MON"
Or InStr(UCase(sLine), "TUE"
Or InStr(UCase(sLine), "WED"
Or InStr(UCase(sLine), "THU"
Or InStr(UCase(sLine), "FRI"
Or InStr(UCase(sLine), "SAT"
Or InStr(UCase(sLine), "SAT"
Then
sLine = objReader.ReadLine() : CurrentLineNo = CurrentLineNo + 1
If InStr(UCase(sLine), "ERROR"
Then arrText.Add(sLine)
While sLine <> ""
sLine = objReader.ReadLine() : CurrentLineNo = CurrentLineNo + 1
End While
End If
End If
If Not sLine Is Nothing Then
End If
Loop Until sLine Is Nothing
objReader.Close()
'create mail notification
Dim mailMsg As New System.Web.Mail.MailMessage
mailMsg.BodyFormat = Mail.MailFormat.Text
mailMsg.To = "???"
mailMsg.Subject = "???"
mailMsg.From = "???"
Dim txtBody As String
For Each sLine In arrText
txtBody = txtBody & sLine & vbCrLf
Next
mailMsg.Body = txtBody
System.Web.Mail.SmtpMail.SmtpServer = "???"
System.Web.Mail.SmtpMail.Send(mailMsg)
SaveSetting("OrEm", "Settings", "LineNo", Trim(Str(CurrentLineNo - 2)))
LineNo = Val(GetSetting("OrEM", "Settings", "LineNo"
)
' myTimer.Start()
'adds the event and the event handler for the method that will process the timer event to the timer
AddHandler myTimer.Tick, AddressOf TimerEventProcessor
CurrentLineNo = 0
'sets the timer interval to 5 minutes
myTimer.Interval = 30000
myTimer.Start()
'runs the timer, and raises the event
' While exitFlag = False
'Processes all the events in the queue
Application.DoEvents()
'End While
End Sub
Any help much appreciated. Thanx.
i've created a program that basically reads a file, checks for the word "error" and then emails sum1 with the "errors". What i need to do now is set the program to read the file every 5 minutes, which ive tried to do but i've messed up somewhere?! when the file has been read, it only sends new errors via email. here is my code:
Imports System
Imports System.IO
Imports System.Collections
Imports System.Web
Public Class Form1
Inherits System.Windows.Forms.Form
Private Shared myTimer As New System.Windows.Forms.Timer
'Private Shared exitFlag As Boolean = False
Private Shared Sub TimerEventProcessor(ByVal myObject As Object, ByVal myEventArgs As EventArgs)
myTimer.Stop()
Dim LineNo As String
Dim CurrentLineNo As New Integer
If GetSetting("OrEM", "Settings", "LineNo"
SaveSetting("OrEM", "Settings", "LineNo", "1"
End If
LineNo = Val(GetSetting("OrEM", "Settings", "LineNo"
Dim objReader As New StreamReader("c:\ProjectSearch\sx3liveALRT.LOG"
Dim sLine As String = ""
Dim arrText As New ArrayList
Do
sLine = objReader.ReadLine() : CurrentLineNo = CurrentLineNo + 1
If CurrentLineNo >= LineNo Then
If InStr(UCase(sLine), "MON"
sLine = objReader.ReadLine() : CurrentLineNo = CurrentLineNo + 1
If InStr(UCase(sLine), "ERROR"
While sLine <> ""
sLine = objReader.ReadLine() : CurrentLineNo = CurrentLineNo + 1
End While
End If
End If
If Not sLine Is Nothing Then
End If
Loop Until sLine Is Nothing
objReader.Close()
'create mail notification
Dim mailMsg As New System.Web.Mail.MailMessage
mailMsg.BodyFormat = Mail.MailFormat.Text
mailMsg.To = "???"
mailMsg.Subject = "???"
mailMsg.From = "???"
Dim txtBody As String
For Each sLine In arrText
txtBody = txtBody & sLine & vbCrLf
Next
mailMsg.Body = txtBody
System.Web.Mail.SmtpMail.SmtpServer = "???"
System.Web.Mail.SmtpMail.Send(mailMsg)
SaveSetting("OrEm", "Settings", "LineNo", Trim(Str(CurrentLineNo - 2)))
LineNo = Val(GetSetting("OrEM", "Settings", "LineNo"
' myTimer.Start()
'adds the event and the event handler for the method that will process the timer event to the timer
AddHandler myTimer.Tick, AddressOf TimerEventProcessor
CurrentLineNo = 0
'sets the timer interval to 5 minutes
myTimer.Interval = 30000
myTimer.Start()
'runs the timer, and raises the event
' While exitFlag = False
'Processes all the events in the queue
Application.DoEvents()
'End While
End Sub
Any help much appreciated. Thanx.