By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,610 Members | 1,957 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,610 IT Pros & Developers. It's quick & easy.

VB.Net Console app needs timer

P: n/a
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.FileSystem.WriteAllText("C:\Test.txt",
String.Empty, False)
'write file header
My.Computer.FileSystem.WriteAllText("C:\Test.txt", "Heartbeat
File" & vbCrLf, True)
'write current date/time to file
My.Computer.FileSystem.WriteAllText("C:\Test.txt", Now() &
vbCrLf, True)
Scott

Jul 5 '07 #1
Share this Question
Share on Google+
15 Replies


P: n/a
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.FileSystem.WriteAllText("C:\Test.txt",
String.Empty, False)
'write file header
My.Computer.FileSystem.WriteAllText("C:\Test.txt", "Heartbeat
File" & vbCrLf, True)
'write current date/time to file
My.Computer.FileSystem.WriteAllText("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(ByVal sender As Object, ByVal e As
EventArgs)
Using writer As New System.IO.StreamWriter("C:\Test.txt")
writer.WriteLine("Heartbeat File")
writer.WriteLine(DateTime.Now)
End Using
End Sub

End Module

Thanks,

Seth Rowe

Jul 5 '07 #2

P: n/a
On Jul 5, 1:40 pm, rowe_newsgroups <rowe_em...@yahoo.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.FileSystem.WriteAllText("C:\Test.txt",
String.Empty, False)
'write file header
My.Computer.FileSystem.WriteAllText("C:\Test.txt", "Heartbeat
File" & vbCrLf, True)
'write current date/time to file
My.Computer.FileSystem.WriteAllText("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(ByVal sender As Object, ByVal e As
EventArgs)
Using writer As New System.IO.StreamWriter("C:\Test.txt")
writer.WriteLine("Heartbeat File")
writer.WriteLine(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

Jul 5 '07 #3

P: n/a
Why not use the scheduler?

--
cheers,
RL
"Scott M." <qu*****@gmail.comwrote in message
news:11**********************@m36g2000hse.googlegr oups.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.FileSystem.WriteAllText("C:\Test.txt",
String.Empty, False)
'write file header
My.Computer.FileSystem.WriteAllText("C:\Test.txt", "Heartbeat
File" & vbCrLf, True)
'write current date/time to file
My.Computer.FileSystem.WriteAllText("C:\Test.txt", Now() &
vbCrLf, True)
Scott

Jul 5 '07 #4

P: n/a
On Jul 5, 2:41 pm, "Egghead" <robertlo@NO_SHAW.CAwrote:
Why not use the scheduler?

--
cheers,
RL"Scott M." <quan...@gmail.comwrote in message

news:11**********************@m36g2000hse.googlegr oups.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.FileSystem.WriteAllText("C:\Test.txt",
String.Empty, False)
'write file header
My.Computer.FileSystem.WriteAllText("C:\Test.txt", "Heartbeat
File" & vbCrLf, True)
'write current date/time to file
My.Computer.FileSystem.WriteAllText("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?

Jul 5 '07 #5

P: n/a

"Scott M." <qu*****@gmail.comwrote in message
news:11*********************@q75g2000hsh.googlegro ups.com...
On Jul 5, 2:41 pm, "Egghead" <robertlo@NO_SHAW.CAwrote:
>Why not use the scheduler?

--
cheers,
RL"Scott M." <quan...@gmail.comwrote in message

news:11**********************@m36g2000hse.googleg roups.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.FileSystem.WriteAllText("C:\Test.txt",
String.Empty, False)
'write file header
My.Computer.FileSystem.WriteAllText("C:\Test.txt", "Heartbeat
File" & vbCrLf, True)
'write current date/time to file
My.Computer.FileSystem.WriteAllText("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
Jul 5 '07 #6

P: n/a
On Jul 5, 3:08 pm, "Al G" <agerha...@charter.netwrote:
"Scott M." <quan...@gmail.comwrote in message

news:11*********************@q75g2000hsh.googlegro ups.com...


On Jul 5, 2:41 pm, "Egghead" <robertlo@NO_SHAW.CAwrote:
Why not use the scheduler?
--
cheers,
RL"Scott M." <quan...@gmail.comwrote in message
>news:11**********************@m36g2000hse.googleg roups.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.FileSystem.WriteAllText("C:\Test.txt",
String.Empty, False)
'write file header
My.Computer.FileSystem.WriteAllText("C:\Test.txt", "Heartbeat
File" & vbCrLf, True)
'write current date/time to file
My.Computer.FileSystem.WriteAllText("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.

Jul 5 '07 #7

P: n/a

"Scott M." <qu*****@gmail.comwrote in message
news:11**********************@i13g2000prf.googlegr oups.com...
On Jul 5, 3:08 pm, "Al G" <agerha...@charter.netwrote:
>"Scott M." <quan...@gmail.comwrote in message

news:11*********************@q75g2000hsh.googlegr oups.com...


On Jul 5, 2:41 pm, "Egghead" <robertlo@NO_SHAW.CAwrote:
Why not use the scheduler?
>--
cheers,
RL"Scott M." <quan...@gmail.comwrote in message
>>news:11**********************@m36g2000hse.google groups.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.FileSystem.WriteAllText("C:\Test.txt",
String.Empty, False)
'write file header
My.Computer.FileSystem.WriteAllText("C:\Test.txt", "Heartbeat
File" & vbCrLf, True)
'write current date/time to file
My.Computer.FileSystem.WriteAllText("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.
>
Jul 5 '07 #8

P: n/a
On Jul 5, 2:52 pm, "Scott M." <quan...@gmail.comwrote:
On Jul 5, 3:08 pm, "Al G" <agerha...@charter.netwrote:
"Scott M." <quan...@gmail.comwrote in message
news:11*********************@q75g2000hsh.googlegro ups.com...
On Jul 5, 2:41 pm, "Egghead" <robertlo@NO_SHAW.CAwrote:
>Why not use the scheduler?
>--
>cheers,
>RL"Scott M." <quan...@gmail.comwrote in message
>>news:11**********************@m36g2000hse.google groups.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.FileSystem.WriteAllText("C:\Test.txt",
String.Empty, False)
'write file header
My.Computer.FileSystem.WriteAllText("C:\Test.txt", "Heartbeat
File" & vbCrLf, True)
'write current date/time to file
My.Computer.FileSystem.WriteAllText("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

Jul 6 '07 #9

P: n/a
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...@charter.netwrote:
"Scott M." <quan...@gmail.comwrote in message
>news:11*********************@q75g2000hsh.googlegr oups.com...
On Jul 5, 2:41 pm, "Egghead" <robertlo@NO_SHAW.CAwrote:
Why not use the scheduler?
--
cheers,
RL"Scott M." <quan...@gmail.comwrote in message
>news:11**********************@m36g2000hse.googleg roups.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.FileSystem.WriteAllText("C:\Test.txt",
String.Empty, False)
'write file header
My.Computer.FileSystem.WriteAllText("C:\Test.txt", "Heartbeat
File" & vbCrLf, True)
'write current date/time to file
My.Computer.FileSystem.WriteAllText("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

Jul 6 '07 #10

P: n/a
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

Jul 6 '07 #11

P: n/a
On Jul 6, 11:45 am, "Mark S. Milley, MCSD (BinarySwitch)"
<mark.mil...@binaryswitch.comwrote:
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

Jul 6 '07 #12

P: n/a
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.

Jul 6 '07 #13

P: n/a
On Jul 6, 12:35 pm, "Mr. Arnold" <MR. Arn...@Arnold.comwrote:
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
LearnVisualStudio.net to start my learning curve.

Scott

Jul 6 '07 #14

P: n/a
Hi Scott -

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

Never give up,

-Mark

Jul 6 '07 #15

P: n/a
I would just add the 1 line of code below to make it "sleep" for a certain
amount of milliseconds. 600,000 milliseconds is approx. 10 minutes.

System.Threading.Thread.Sleep(600000)
"Scott M." wrote:
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.FileSystem.WriteAllText("C:\Test.txt",
String.Empty, False)
'write file header
My.Computer.FileSystem.WriteAllText("C:\Test.txt", "Heartbeat
File" & vbCrLf, True)
'write current date/time to file
My.Computer.FileSystem.WriteAllText("C:\Test.txt", Now() &
vbCrLf, True)
Scott

Aug 13 '07 #16

This discussion thread is closed

Replies have been disabled for this discussion.