H
Hotrod2000
I'm quite new to programming but I'm having problems getting a timer
to work in visual studio.net
I've created a timer on a form, enabled it and then typed the
following code (from the mdsn library as I thought this would be a
good start!!!) but nothing happens :-
Imports System.Timers
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Timer1 As System.Windows.Forms.Timer
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim configurationAppSettings As
System.Configuration.AppSettingsReader = New
System.Configuration.AppSettingsReader
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
'
'Timer1
'
Me.Timer1.Enabled =
CType(configurationAppSettings.GetValue("Timer1.Enabled",
GetType(System.Boolean)), Boolean)
Me.Timer1.Interval =
CType(configurationAppSettings.GetValue("Timer1.Interval",
GetType(System.Int32)), Integer)
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Name = "Form1"
Me.Text = "Form1"
End Sub
#End Region
End Class
Public Class Timer1
Public Shared Sub Main()
Dim aTimer As New System.Timers.Timer
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
aTimer.Interval = 2000
aTimer.Enabled = True
Console.WriteLine("Press the Enter key to exit the program.")
Console.ReadLine()
GC.KeepAlive(aTimer)
End Sub
Private Shared Sub OnTimedEvent(ByVal source As Object, ByVal e
As
ElapsedEventArgs)
Console.WriteLine("Hello World!")
End Sub
End Class
Any help would be greatly appreciated.
Thanks
Paul
to work in visual studio.net
I've created a timer on a form, enabled it and then typed the
following code (from the mdsn library as I thought this would be a
good start!!!) but nothing happens :-
Imports System.Timers
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Timer1 As System.Windows.Forms.Timer
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim configurationAppSettings As
System.Configuration.AppSettingsReader = New
System.Configuration.AppSettingsReader
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
'
'Timer1
'
Me.Timer1.Enabled =
CType(configurationAppSettings.GetValue("Timer1.Enabled",
GetType(System.Boolean)), Boolean)
Me.Timer1.Interval =
CType(configurationAppSettings.GetValue("Timer1.Interval",
GetType(System.Int32)), Integer)
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Name = "Form1"
Me.Text = "Form1"
End Sub
#End Region
End Class
Public Class Timer1
Public Shared Sub Main()
Dim aTimer As New System.Timers.Timer
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
aTimer.Interval = 2000
aTimer.Enabled = True
Console.WriteLine("Press the Enter key to exit the program.")
Console.ReadLine()
GC.KeepAlive(aTimer)
End Sub
Private Shared Sub OnTimedEvent(ByVal source As Object, ByVal e
As
ElapsedEventArgs)
Console.WriteLine("Hello World!")
End Sub
End Class
Any help would be greatly appreciated.
Thanks
Paul