VB.Net控制台应用程序需要计时器 [英] VB.Net Console app needs timer
问题描述
我是一个很老的VB6人,刚刚在VB.Net中使用Visual Studio开始
Express。我想构建一个简单的控制台应用程序,每10分钟创建一个
简单文本文件。我可以创建文件OK,但是如何将
放入计时器以便我可以按计划编写文件?这个项目背后的想法是帮助我监控
生产环境中的远程计算机,以确保它们正常运行。我现在使用DriveHQ.com同步
。我想要的是b $ b,我可以查看我的DriveHQ帐户,并从文本文件中看到我的系统启动并运行的内容。 br />
到目前为止,应用程序编码是这样的;
''创建文件
My.Computer.FileSystem.WriteAllText (" C:\ Test.txt",
String.Empty,False)
''写文件头
My.Computer .FileSystem.WriteAllText(" C:\ Test.txt"," Heartbeat
File"& vbCrLf,True)
''写当前日期/时间提交
My.Computer.FileSystem.WriteAllText(" C:\ Test.txt",Now()&
vbCrLf,True)
Scott
7月5日下午1:30,Scott M. < quan ... @ gmail.comwrote:
我是一个老的VB6家伙使用Visual Studio从VB.Net开始
Express。我想构建一个简单的控制台应用程序,每10分钟创建一个
简单文本文件。我可以创建文件OK,但是如何将
放入计时器以便我可以按计划编写文件?这个项目背后的想法是帮助我监控
生产环境中的远程计算机,以确保它们正常运行。我现在使用DriveHQ.com同步
。我想要的是b $ b,我可以查看我的DriveHQ帐户,并从文本文件中看到我的系统启动并运行的内容。 br />
到目前为止,应用程序编码是这样的;
''创建文件
My.Computer.FileSystem.WriteAllText (" C:\ Test.txt",
String.Empty,False)
''写文件头
My.Computer .FileSystem.WriteAllText(" C:\ Test.txt"," Heartbeat
File"& vbCrLf,True)
''写当前日期/时间提交
My.Computer.FileSystem.WriteAllText(" C:\ Test.txt",Now()&
vbCrLf,True)
Scott
这可能不是正确的方式 - 但我从不关心
。 :-)
我首先将System.Windows.Forms的引用添加到我的项目
并执行此操作:
Imports System.Windows.Forms
模块模块1
Sub Main()
Dim t作为新计时器
t.Interval = 600000''//我认为10分钟= 600,000
毫秒:-)
AddHandler t.Tick ,AddressOf timer_Tick
t.Start()
Application.Run()
End Sub
>
Public Sub timer_Tick(ByVal sender As Object,ByVal e As
EventArgs)
使用writer As New System.IO.StreamWriter(" C:\\ \\ test.txt")
writer.WriteLine(" Heartbeat File")
writer.WriteLine(DateTime.Now)
结束使用
结束子
结束模块
谢谢,
Seth Rowe
7月5日下午1:40,rowe_newsgroups< rowe_em ... @ yahoo.comwrote:
7月5日下午1:30,Scott M. < quan ... @ gmail.comwrote:
I 是一个老VB6的人刚刚在VB.Net中使用Visual Studio开始
Express。我想构建一个简单的控制台应用程序,每10分钟创建一个
简单文本文件。我可以创建文件OK,但是如何将
放入计时器以便我可以按计划编写文件?这个项目背后的想法是帮助我监控
生产环境中的远程计算机,以确保它们正常运行。我现在使用DriveHQ.com同步
。我想要的是b $ b,能够检查我的DriveHQ帐户,并从文本文件中看到我的系统启动并运行的内容。
到目前为止,应用程序编码是这样的;
''创建文件
My.Computer.FileSystem.WriteAllText(" C:\ Test.txt" ,
String.Empty,False)
''写文件头
My.Computer.FileSystem.WriteAllText(" C:\ Test.txt"," Heartbeat
File"& vbCrLf,True)
''将当前日期/时间写入文件
我的.Computer.FileSystem.WriteAllText(" C:\ Test.txt",Now()&
vbCrLf,True)
Scott
这可能不是正确的方式 - 但我从不关心
。 :-)
我首先将System.Windows.Forms的引用添加到我的项目
并执行此操作:
Imports System.Windows.Forms
模块模块1
Sub Main()
Dim t作为新计时器
t.Interval = 600000''//我认为10分钟= 600,000
毫秒:-)
AddHandler t.Tick ,AddressOf timer_Tick
t.Start()
Application.Run()
End Sub
>
Public Sub timer_Tick(ByVal sender As Object,ByVal e As
EventArgs)
使用writer As New System.IO.StreamWriter(" C:\\ \\ test.txt")
writer.WriteLine(" Heartbeat File")
writer.WriteLine(DateTime.Now)
结束使用
结束子
结束模块
谢谢,
Seth Rowe
我rgot to add - 在控制台中使用System.Windows.Forms计时器
项目被一些人视为禁忌 - 你可以使用其他
可用的计时器如果你想要,但我更喜欢简单的表格
计时器。
谢谢,
Seth Rowe
为什么不使用调度程序?
-
欢呼,>
RL
" Scott M." < qu ***** @ gmail.com写信息
news:11 ********************** @ m36g2000hse。 googlegr oups.com ...
我是一个刚开始用VB的老VB6人.Net使用Visual Studio
Express。我想构建一个简单的控制台应用程序,每10分钟创建一个
简单文本文件。我可以创建文件OK,但是如何将
放入计时器以便我可以按计划编写文件?这个项目背后的想法是帮助我监控
生产环境中的远程计算机,以确保它们正常运行。我现在使用DriveHQ.com同步
。我想要的是b $ b,我可以查看我的DriveHQ帐户,并从文本文件中看到我的系统启动并运行的内容。 br />
到目前为止,应用程序编码是这样的;
''创建文件
My.Computer.FileSystem.WriteAllText (" C:\ Test.txt",
String.Empty,False)
''写文件头
My.Computer .FileSystem.WriteAllText(" C:\ Test.txt"," Heartbeat
File"& vbCrLf,True)
''写当前日期/时间提交
My.Computer.FileSystem.WriteAllText(" C:\ Test.txt",Now()&
vbCrLf,True)
Scott
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
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)
ScottThis 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
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 RoweI 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
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
这篇关于VB.Net控制台应用程序需要计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!