VB.Net Console app needs timer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Scott M.

    VB.Net Console app needs timer

    Hi,

    I'm an old VB6 guy just starting out in VB.Net using Visual Studio
    Express. I want to build a simple console app that will create a
    simple text file every 10 minutes. I can create the file OK, but how
    do I put in the timer so that I can write the file on schedule? The
    idea behind this project is to help me monitor remote computers in a
    production environment to make sure that they are up and running. I
    currently synchronize files on them using DriveHQ.com. What I want to
    do is be able to examine my DriveHQ account and see, from what I write
    in the text file, that my systems are up and running.

    The app coding so far is this;

    'create file
    My.Computer.Fil eSystem.WriteAl lText("C:\Test. txt",
    String.Empty, False)
    'write file header
    My.Computer.Fil eSystem.WriteAl lText("C:\Test. txt", "Heartbeat
    File" & vbCrLf, True)
    'write current date/time to file
    My.Computer.Fil eSystem.WriteAl lText("C:\Test. txt", Now() &
    vbCrLf, True)


    Scott

  • rowe_newsgroups

    #2
    Re: VB.Net Console app needs timer

    On Jul 5, 1:30 pm, "Scott M." <quan...@gmail. comwrote:
    Hi,
    >
    I'm an old VB6 guy just starting out in VB.Net using Visual Studio
    Express. I want to build a simple console app that will create a
    simple text file every 10 minutes. I can create the file OK, but how
    do I put in the timer so that I can write the file on schedule? The
    idea behind this project is to help me monitor remote computers in a
    production environment to make sure that they are up and running. I
    currently synchronize files on them using DriveHQ.com. What I want to
    do is be able to examine my DriveHQ account and see, from what I write
    in the text file, that my systems are up and running.
    >
    The app coding so far is this;
    >
    'create file
    My.Computer.Fil eSystem.WriteAl lText("C:\Test. txt",
    String.Empty, False)
    'write file header
    My.Computer.Fil eSystem.WriteAl lText("C:\Test. txt", "Heartbeat
    File" & vbCrLf, True)
    'write current date/time to file
    My.Computer.Fil eSystem.WriteAl lText("C:\Test. txt", Now() &
    vbCrLf, True)
    >
    Scott
    This may not be the "proper" way - but I never cared about being
    proper. :-)

    I would first add a reference to System.Windows. Forms to my project
    and do this:

    Imports System.Windows. Forms

    Module Module1

    Sub Main()
    Dim t As New Timer
    t.Interval = 600000 '// I think 10 minutes = 600,000
    milliseconds :-)
    AddHandler t.Tick, AddressOf timer_Tick
    t.Start()

    Application.Run ()
    End Sub

    Public Sub timer_Tick(ByVa l sender As Object, ByVal e As
    EventArgs)
    Using writer As New System.IO.Strea mWriter("C:\Tes t.txt")
    writer.WriteLin e("Heartbeat File")
    writer.WriteLin e(DateTime.Now)
    End Using
    End Sub

    End Module

    Thanks,

    Seth Rowe

    Comment

    • rowe_newsgroups

      #3
      Re: VB.Net Console app needs timer

      On Jul 5, 1:40 pm, rowe_newsgroups <rowe_em...@yah oo.comwrote:
      On Jul 5, 1:30 pm, "Scott M." <quan...@gmail. comwrote:
      >
      >
      >
      Hi,
      >
      I'm an old VB6 guy just starting out in VB.Net using Visual Studio
      Express. I want to build a simple console app that will create a
      simple text file every 10 minutes. I can create the file OK, but how
      do I put in the timer so that I can write the file on schedule? The
      idea behind this project is to help me monitor remote computers in a
      production environment to make sure that they are up and running. I
      currently synchronize files on them using DriveHQ.com. What I want to
      do is be able to examine my DriveHQ account and see, from what I write
      in the text file, that my systems are up and running.
      >
      The app coding so far is this;
      >
      'create file
      My.Computer.Fil eSystem.WriteAl lText("C:\Test. txt",
      String.Empty, False)
      'write file header
      My.Computer.Fil eSystem.WriteAl lText("C:\Test. txt", "Heartbeat
      File" & vbCrLf, True)
      'write current date/time to file
      My.Computer.Fil eSystem.WriteAl lText("C:\Test. txt", Now() &
      vbCrLf, True)
      >
      Scott
      >
      This may not be the "proper" way - but I never cared about being
      proper. :-)
      >
      I would first add a reference to System.Windows. Forms to my project
      and do this:
      >
      Imports System.Windows. Forms
      >
      Module Module1
      >
      Sub Main()
      Dim t As New Timer
      t.Interval = 600000 '// I think 10 minutes = 600,000
      milliseconds :-)
      AddHandler t.Tick, AddressOf timer_Tick
      t.Start()
      >
      Application.Run ()
      End Sub
      >
      Public Sub timer_Tick(ByVa l sender As Object, ByVal e As
      EventArgs)
      Using writer As New System.IO.Strea mWriter("C:\Tes t.txt")
      writer.WriteLin e("Heartbeat File")
      writer.WriteLin e(DateTime.Now)
      End Using
      End Sub
      >
      End Module
      >
      Thanks,
      >
      Seth Rowe
      I forgot to add - using the System.Windows. Forms timer in a console
      project is considered a no-no by some - you can use the other
      available timers if you want, but I prefer the simplicity of the Forms
      timer.

      Thanks,

      Seth Rowe

      Comment

      • Egghead

        #4
        Re: VB.Net Console app needs timer

        Why not use the scheduler?

        --
        cheers,
        RL
        "Scott M." <quanker@gmail. comwrote in message
        news:1183656651 .419053.180430@ m36g2000hse.goo glegroups.com.. .
        Hi,
        >
        I'm an old VB6 guy just starting out in VB.Net using Visual Studio
        Express. I want to build a simple console app that will create a
        simple text file every 10 minutes. I can create the file OK, but how
        do I put in the timer so that I can write the file on schedule? The
        idea behind this project is to help me monitor remote computers in a
        production environment to make sure that they are up and running. I
        currently synchronize files on them using DriveHQ.com. What I want to
        do is be able to examine my DriveHQ account and see, from what I write
        in the text file, that my systems are up and running.
        >
        The app coding so far is this;
        >
        'create file
        My.Computer.Fil eSystem.WriteAl lText("C:\Test. txt",
        String.Empty, False)
        'write file header
        My.Computer.Fil eSystem.WriteAl lText("C:\Test. txt", "Heartbeat
        File" & vbCrLf, True)
        'write current date/time to file
        My.Computer.Fil eSystem.WriteAl lText("C:\Test. txt", Now() &
        vbCrLf, True)
        >
        >
        Scott
        >

        Comment

        • Scott M.

          #5
          Re: VB.Net Console app needs timer

          On Jul 5, 2:41 pm, "Egghead" <robertlo@NO_SH AW.CAwrote:
          Why not use the scheduler?
          >
          --
          cheers,
          RL"Scott M." <quan...@gmail. comwrote in message
          >
          news:1183656651 .419053.180430@ m36g2000hse.goo glegroups.com.. .
          >
          >
          >
          Hi,
          >
          I'm an old VB6 guy just starting out in VB.Net using Visual Studio
          Express. I want to build a simple console app that will create a
          simple text file every 10 minutes. I can create the file OK, but how
          do I put in the timer so that I can write the file on schedule? The
          idea behind this project is to help me monitor remote computers in a
          production environment to make sure that they are up and running. I
          currently synchronize files on them using DriveHQ.com. What I want to
          do is be able to examine my DriveHQ account and see, from what I write
          in the text file, that my systems are up and running.
          >
          The app coding so far is this;
          >
          'create file
          My.Computer.Fil eSystem.WriteAl lText("C:\Test. txt",
          String.Empty, False)
          'write file header
          My.Computer.Fil eSystem.WriteAl lText("C:\Test. txt", "Heartbeat
          File" & vbCrLf, True)
          'write current date/time to file
          My.Computer.Fil eSystem.WriteAl lText("C:\Test. txt", Now() &
          vbCrLf, True)
          >
          Scott- Hide quoted text -
          >
          - Show quoted text -
          I am too new to VB2005 to know how to use it. Can you give me a hint?

          Comment

          • Al  G

            #6
            Re: VB.Net Console app needs timer


            "Scott M." <quanker@gmail. comwrote in message
            news:1183661709 .081614.76360@q 75g2000hsh.goog legroups.com...
            On Jul 5, 2:41 pm, "Egghead" <robertlo@NO_SH AW.CAwrote:
            >Why not use the scheduler?
            >>
            >--
            >cheers,
            >RL"Scott M." <quan...@gmail. comwrote in message
            >>
            >news:118365665 1.419053.180430 @m36g2000hse.go oglegroups.com. ..
            >>
            >>
            >>
            Hi,
            >>
            I'm an old VB6 guy just starting out in VB.Net using Visual Studio
            Express. I want to build a simple console app that will create a
            simple text file every 10 minutes. I can create the file OK, but how
            do I put in the timer so that I can write the file on schedule? The
            idea behind this project is to help me monitor remote computers in a
            production environment to make sure that they are up and running. I
            currently synchronize files on them using DriveHQ.com. What I want to
            do is be able to examine my DriveHQ account and see, from what I write
            in the text file, that my systems are up and running.
            >>
            The app coding so far is this;
            >>
            'create file
            My.Computer.Fil eSystem.WriteAl lText("C:\Test. txt",
            String.Empty, False)
            'write file header
            My.Computer.Fil eSystem.WriteAl lText("C:\Test. txt", "Heartbeat
            File" & vbCrLf, True)
            'write current date/time to file
            My.Computer.Fil eSystem.WriteAl lText("C:\Test. txt", Now() &
            vbCrLf, True)
            >>
            Scott- Hide quoted text -
            >>
            >- Show quoted text -
            >
            I am too new to VB2005 to know how to use it. Can you give me a hint?
            >
            Start Menu Settings Control Panel Scheduled Tasks Add Task...

            Al G


            Comment

            • Scott M.

              #7
              Re: VB.Net Console app needs timer

              On Jul 5, 3:08 pm, "Al G" <agerha...@char ter.netwrote:
              "Scott M." <quan...@gmail. comwrote in message
              >
              news:1183661709 .081614.76360@q 75g2000hsh.goog legroups.com...
              >
              >
              >
              >
              >
              On Jul 5, 2:41 pm, "Egghead" <robertlo@NO_SH AW.CAwrote:
              Why not use the scheduler?
              >
              --
              cheers,
              RL"Scott M." <quan...@gmail. comwrote in message
              >
              >news:118365665 1.419053.180430 @m36g2000hse.go oglegroups.com. ..
              >
              Hi,
              >
              I'm an old VB6 guy just starting out in VB.Net using Visual Studio
              Express. I want to build a simple console app that will create a
              simple text file every 10 minutes. I can create the file OK, but how
              do I put in the timer so that I can write the file on schedule? The
              idea behind this project is to help me monitor remote computers in a
              production environment to make sure that they are up and running. I
              currently synchronize files on them using DriveHQ.com. What I want to
              do is be able to examine my DriveHQ account and see, from what I write
              in the text file, that my systems are up and running.
              >
              The app coding so far is this;
              >
              'create file
              My.Computer.Fil eSystem.WriteAl lText("C:\Test. txt",
              String.Empty, False)
              'write file header
              My.Computer.Fil eSystem.WriteAl lText("C:\Test. txt", "Heartbeat
              File" & vbCrLf, True)
              'write current date/time to file
              My.Computer.Fil eSystem.WriteAl lText("C:\Test. txt", Now() &
              vbCrLf, True)
              >
              Scott- Hide quoted text -
              >
              - Show quoted text -
              >
              I am too new to VB2005 to know how to use it. Can you give me a hint?
              >
              Start Menu Settings Control Panel Scheduled Tasks Add Task...
              >
              Al G- Hide quoted text -
              >
              - Show quoted text -
              Oh, that scheduler. I can use it to launch my tiny program, but I need
              the program to write out my heartbeat file every ten minutes. I could
              just as easily put my program in the startup folder.

              Comment

              • Mr. Arnold

                #8
                Re: VB.Net Console app needs timer


                "Scott M." <quanker@gmail. comwrote in message
                news:1183665174 .237208.238030@ i13g2000prf.goo glegroups.com.. .
                On Jul 5, 3:08 pm, "Al G" <agerha...@char ter.netwrote:
                >"Scott M." <quan...@gmail. comwrote in message
                >>
                >news:118366170 9.081614.76360@ q75g2000hsh.goo glegroups.com.. .
                >>
                >>
                >>
                >>
                >>
                On Jul 5, 2:41 pm, "Egghead" <robertlo@NO_SH AW.CAwrote:
                >Why not use the scheduler?
                >>
                >--
                >cheers,
                >RL"Scott M." <quan...@gmail. comwrote in message
                >>
                >>news:11836566 51.419053.18043 0@m36g2000hse.g ooglegroups.com ...
                >>
                Hi,
                >>
                I'm an old VB6 guy just starting out in VB.Net using Visual Studio
                Express. I want to build a simple console app that will create a
                simple text file every 10 minutes. I can create the file OK, but how
                do I put in the timer so that I can write the file on schedule? The
                idea behind this project is to help me monitor remote computers in a
                production environment to make sure that they are up and running. I
                currently synchronize files on them using DriveHQ.com. What I want
                to
                do is be able to examine my DriveHQ account and see, from what I
                write
                in the text file, that my systems are up and running.
                >>
                The app coding so far is this;
                >>
                'create file
                My.Computer.Fil eSystem.WriteAl lText("C:\Test. txt",
                String.Empty, False)
                'write file header
                My.Computer.Fil eSystem.WriteAl lText("C:\Test. txt", "Heartbeat
                File" & vbCrLf, True)
                'write current date/time to file
                My.Computer.Fil eSystem.WriteAl lText("C:\Test. txt", Now() &
                vbCrLf, True)
                >>
                Scott- Hide quoted text -
                >>
                >- Show quoted text -
                >>
                I am too new to VB2005 to know how to use it. Can you give me a hint?
                >>
                >Start Menu Settings Control Panel Scheduled Tasks Add Task...
                >>
                >Al G- Hide quoted text -
                >>
                >- Show quoted text -
                >
                Oh, that scheduler. I can use it to launch my tiny program, but I need
                the program to write out my heartbeat file every ten minutes. I could
                just as easily put my program in the startup folder.
                What's wrong with using System.Timers name space to create a timer with an
                AddressHandler for the time elasped. I done it in console applications.
                >

                Comment

                • Chris Dunaway

                  #9
                  Re: VB.Net Console app needs timer

                  On Jul 5, 2:52 pm, "Scott M." <quan...@gmail. comwrote:
                  On Jul 5, 3:08 pm, "Al G" <agerha...@char ter.netwrote:
                  >
                  >
                  >
                  "Scott M." <quan...@gmail. comwrote in message
                  >
                  news:1183661709 .081614.76360@q 75g2000hsh.goog legroups.com...
                  >
                  On Jul 5, 2:41 pm, "Egghead" <robertlo@NO_SH AW.CAwrote:
                  >Why not use the scheduler?
                  >
                  >--
                  >cheers,
                  >RL"Scott M." <quan...@gmail. comwrote in message
                  >
                  >>news:11836566 51.419053.18043 0@m36g2000hse.g ooglegroups.com ...
                  >
                  Hi,
                  >
                  I'm an old VB6 guy just starting out in VB.Net using Visual Studio
                  Express. I want to build a simple console app that will create a
                  simple text file every 10 minutes. I can create the file OK, but how
                  do I put in the timer so that I can write the file on schedule? The
                  idea behind this project is to help me monitor remote computers in a
                  production environment to make sure that they are up and running. I
                  currently synchronize files on them using DriveHQ.com. What I want to
                  do is be able to examine my DriveHQ account and see, from what I write
                  in the text file, that my systems are up and running.
                  >
                  The app coding so far is this;
                  >
                  'create file
                  My.Computer.Fil eSystem.WriteAl lText("C:\Test. txt",
                  String.Empty, False)
                  'write file header
                  My.Computer.Fil eSystem.WriteAl lText("C:\Test. txt", "Heartbeat
                  File" & vbCrLf, True)
                  'write current date/time to file
                  My.Computer.Fil eSystem.WriteAl lText("C:\Test. txt", Now() &
                  vbCrLf, True)
                  >
                  Scott- Hide quoted text -
                  >
                  >- Show quoted text -
                  >
                  I am too new to VB2005 to know how to use it. Can you give me a hint?
                  >
                  Start Menu Settings Control Panel Scheduled Tasks Add Task...
                  >
                  Al G- Hide quoted text -
                  >
                  - Show quoted text -
                  >
                  Oh, that scheduler. I can use it to launch my tiny program, but I need
                  the program to write out my heartbeat file every ten minutes. I could
                  just as easily put my program in the startup folder.
                  But that will only launch your program once. Set the scheduled task
                  to run your program every 10 minutes. That way, all you need to do in
                  your program is just create the file and you don't have to worry about
                  the timer.

                  Chris

                  Comment

                  • Scott M.

                    #10
                    Re: VB.Net Console app needs timer

                    On Jul 6, 9:27 am, Chris Dunaway <dunaw...@gmail .comwrote:
                    On Jul 5, 2:52 pm, "Scott M." <quan...@gmail. comwrote:
                    >
                    >
                    >
                    >
                    >
                    On Jul 5, 3:08 pm, "Al G" <agerha...@char ter.netwrote:
                    >
                    "Scott M." <quan...@gmail. comwrote in message
                    >
                    >news:118366170 9.081614.76360@ q75g2000hsh.goo glegroups.com.. .
                    >
                    On Jul 5, 2:41 pm, "Egghead" <robertlo@NO_SH AW.CAwrote:
                    Why not use the scheduler?
                    >
                    --
                    cheers,
                    RL"Scott M." <quan...@gmail. comwrote in message
                    >
                    >news:118365665 1.419053.180430 @m36g2000hse.go oglegroups.com. ..
                    >
                    Hi,
                    >
                    I'm an old VB6 guy just starting out in VB.Net using Visual Studio
                    Express. I want to build a simple console app that will create a
                    simple text file every 10 minutes. I can create the file OK, but how
                    do I put in the timer so that I can write the file on schedule? The
                    idea behind this project is to help me monitor remote computers in a
                    production environment to make sure that they are up and running. I
                    currently synchronize files on them using DriveHQ.com. What I want to
                    do is be able to examine my DriveHQ account and see, from what I write
                    in the text file, that my systems are up and running.
                    >
                    The app coding so far is this;
                    >
                    'create file
                    My.Computer.Fil eSystem.WriteAl lText("C:\Test. txt",
                    String.Empty, False)
                    'write file header
                    My.Computer.Fil eSystem.WriteAl lText("C:\Test. txt", "Heartbeat
                    File" & vbCrLf, True)
                    'write current date/time to file
                    My.Computer.Fil eSystem.WriteAl lText("C:\Test. txt", Now() &
                    vbCrLf, True)
                    >
                    Scott- Hide quoted text -
                    >
                    - Show quoted text -
                    >
                    I am too new to VB2005 to know how to use it. Can you give me a hint?
                    >
                    Start Menu Settings Control Panel Scheduled Tasks Add Task...
                    >
                    Al G- Hide quoted text -
                    >
                    - Show quoted text -
                    >
                    Oh, that scheduler. I can use it to launch my tiny program, but I need
                    the program to write out my heartbeat file every ten minutes. I could
                    just as easily put my program in the startup folder.
                    >
                    But that will only launch your program once. Set the scheduled task
                    to run your program every 10 minutes. That way, all you need to do in
                    your program is just create the file and you don't have to worry about
                    the timer.
                    >
                    Chris- Hide quoted text -
                    >
                    - Show quoted text -
                    I agree with you Chris, but I've looked at Scheduler and I don't think
                    I can launch a task any more than once per day. Try it by setting up
                    NotePad or some other app to run, just to see how often you can get it
                    to run.

                    Scott

                    Comment

                    • Mark S. Milley, MCSD (BinarySwitch)

                      #11
                      Re: VB.Net Console app needs timer

                      Hi Scott -

                      To repeat a task: In the task scheduler, after you create the task, go
                      to the task's properties, then click advanced. There's a checkbox to
                      Repeat the Task, and, conincidentally , the default is every 10
                      minutes.

                      My personal take on which timer you should use: I'm a purist, and I
                      would go with the System.Timers one, since you are not creating a
                      WinForms app. As I understand it, the Windows Forms version has more
                      overhead (not that most people care about memory usage these days.)

                      That said, unless you have some other reason to have your application
                      running all day long, I would do the scheduled task; if you would
                      prefer to have it running 24/7, maybe you should look into creating a
                      windows service (is this possible in express?) instead of a console
                      app....

                      Cheers,

                      -Mark

                      Comment

                      • rowe_newsgroups

                        #12
                        Re: VB.Net Console app needs timer

                        On Jul 6, 11:45 am, "Mark S. Milley, MCSD (BinarySwitch)"
                        <mark.mil...@bi naryswitch.comw rote:
                        Hi Scott -
                        >
                        To repeat a task: In the task scheduler, after you create the task, go
                        to the task's properties, then click advanced. There's a checkbox to
                        Repeat the Task, and, conincidentally , the default is every 10
                        minutes.
                        >
                        My personal take on which timer you should use: I'm a purist, and I
                        would go with the System.Timers one, since you are not creating a
                        WinForms app. As I understand it, the Windows Forms version has more
                        overhead (not that most people care about memory usage these days.)
                        >
                        That said, unless you have some other reason to have your application
                        running all day long, I would do the scheduled task; if you would
                        prefer to have it running 24/7, maybe you should look into creating a
                        windows service (is this possible in express?) instead of a console
                        app....
                        >
                        Cheers,
                        >
                        -Mark
                        windows service (is this possible in express?)
                        I think it is - after all isn't everything included with the .Net
                        framework and not the ide? I mean in reality you could even just write
                        the service with notepad and vbc.exe right?

                        Thanks,

                        Seth Rowe

                        Comment

                        • Mr. Arnold

                          #13
                          Re: VB.Net Console app needs timer

                          windows service (is this possible in express?) instead of a console

                          Yes, you can create service application with Express, by coding it yourself.
                          There is no windows service template for Express, like there is for
                          Professional. There are examples out on Google on how to code the service,
                          in VB or C#.NET.

                          Comment

                          • Scott M.

                            #14
                            Re: VB.Net Console app needs timer

                            On Jul 6, 12:35 pm, "Mr. Arnold" <MR. Arn...@Arnold.c omwrote:
                            windows service (is this possible in express?) instead of a console
                            >
                            Yes, you can create service application with Express, by coding it yourself.
                            There is no windows service template for Express, like there is for
                            Professional. There are examples out on Google on how to code the service,
                            in VB or C#.NET.
                            Hi all,

                            I appreciate all your advice. I decided against a console app because
                            I don't want to see a DOS box pop up. All I want to do is write out a
                            simple file that holds something like;

                            Heartbeat File
                            06/07/2007 1:25:59 PM

                            in it and then overwrites it 10 minutes later (or 20 or 30 or one
                            hour, it doesn't really matter). I can monitor this file remotely and
                            I will know if the computer is up and running by looking at the last
                            timestamp written in the file. I don't need a user interface or a
                            system tray icon or anything. I have never created a service
                            application but I will try to figure out how to do that. It seems like
                            a good solution. Barring that, I can make a simple Windows app, make
                            it hide itself and use the scheduler as Mark indicates.

                            This project must sound pretty lame to you guys, but I am just getting
                            my feet wet with Visual Studio and VB6 hasn't prepared me at all for
                            the realities of true OO Programming. I even signed up with
                            LearnVisualStud io.net to start my learning curve.

                            Scott

                            Comment

                            • Mark S. Milley, MCSD (BinarySwitch)

                              #15
                              Re: VB.Net Console app needs timer

                              Hi Scott -

                              Don't worry, it's actually easier; you're just experiencing a paradigm
                              shift.

                              Never give up,

                              -Mark

                              Comment

                              Working...