Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. vb.net, timer, run program every 5 mins

vb.net, timer, run program every 5 mins

Scheduled Pinned Locked Moved Visual Basic
helpcsharpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chrissy Callen
    wrote on last edited by
    #1

    Hi :) ive created a program that will read a file, check it for the word "error" and then email me with a list of all new errors in the file. im now trying to get the program to read the file every 5 minutes and then send email notification only if there are new errors - could some1 pls help? here's my code so far, which was working until i started to get the timer working! 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) S

    R 1 Reply Last reply
    0
    • C Chrissy Callen

      Hi :) ive created a program that will read a file, check it for the word "error" and then email me with a list of all new errors in the file. im now trying to get the program to read the file every 5 minutes and then send email notification only if there are new errors - could some1 pls help? here's my code so far, which was working until i started to get the timer working! 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) S

      R Offline
      R Offline
      Ray Cassick
      wrote on last edited by
      #2

      Since I am not sure what OS you are running on I can’t make a concrete recommendation but why not use the available system scheduler that exists in the OS and not worry about that part in your application. Most OS today offer some type of scheduler to automate tasks running at specific intervals.


      Paul Watson wrote: "At the end of the day it is what you produce that counts, not how many doctorates you have on the wall." George Carlin wrote: "Don't sweat the petty things, and don't pet the sweaty things." Jörgen Sigvardsson wrote: If the physicists find a universal theory describing the laws of universe, I'm sure the asshole constant will be an integral part of that theory.


      C 1 Reply Last reply
      0
      • R Ray Cassick

        Since I am not sure what OS you are running on I can’t make a concrete recommendation but why not use the available system scheduler that exists in the OS and not worry about that part in your application. Most OS today offer some type of scheduler to automate tasks running at specific intervals.


        Paul Watson wrote: "At the end of the day it is what you produce that counts, not how many doctorates you have on the wall." George Carlin wrote: "Don't sweat the petty things, and don't pet the sweaty things." Jörgen Sigvardsson wrote: If the physicists find a universal theory describing the laws of universe, I'm sure the asshole constant will be an integral part of that theory.


        C Offline
        C Offline
        Chrissy Callen
        wrote on last edited by
        #3

        Hi there :) Ok, the timers seems fine now, next prob is this: I want the program to email only if the file contains new "errors" but NOT to email if there are no new instances of the "error" word. so i wrapped the mail code in if sline <> "" then ... (mail code)...end if and it doesnt seem to mail at all now (i added errors manually to the file to check it). Could u pls tell me where im going wrong? Thanx! Imports System Imports System.IO Imports System.Collections Imports System.Web Module Module1 Sub Main() Dim myTimer As New System.Timers.Timer Dim LineNo As String myTimer.Stop() 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("filename") 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() If sLine <> "" Then 'create mail notification Dim mailMsg As New System.Web.Mail.MailMessage mailMsg.BodyFormat = Mail.MailFormat.Text mailMsg.To = "me@co.uk" mailMsg.Subject = "name" mailMsg.From = "name" Dim txtBody As String For Each sLine In arrText txtBody = txtBody & sLine & vbCrLf Next mailMsg.Body = txtBody System.Web.Mail.SmtpMail.SmtpServer = "server" System.Web.Mail.SmtpMail.Send(mailMsg) End If SaveSetting("OrEm", "Settings", "LineNo", Trim(Str(CurrentLineNo

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups