Hey,
Usually I am over moderating at ASP.Net, but today I have a question for you guys. I have a timer that just is not firing. Can anyone help Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Configuration
Imports System.Windows.Forms
Imports System.IO
Imports System.Data
Public Class Alert
Inherits System.Windows.Forms.Form
Private Timer1 As System.Timers.Timer
Public Sub New()
MyBase.New()
InitializeComponent()
Try
Timer1.Interval = Convert.ToDouble(ConfigurationSettings.AppSettings("CheckInterval"))
Catch
End Try
Me.Hide()
End Sub
'Form overrides dispose to clean up the component list.
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
'Required by the Windows Form Designer
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.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Alert))
Me.Timer1 = New System.Timers.Timer()
AddHandler Timer1.Elapsed, AddressOf timer1_Elapsed
Me.Timer1.BeginInit()
'
'Timer1
'
Me.Timer1.Enabled = True
Me.Timer1.Interval = 4000
Me.Timer1.SynchronizingObject = Me
'
'Alert
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(144, 54)
Me.ControlBox = False
Me.Enabled = False
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.Name = "Alert"
Me.ShowInTaskbar = True
Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual
Me.Text = "HelpDesk Alert"
Me.WindowState = System.Windows.Forms.FormWindowState.Minimized
End Sub
Private Sub timer1_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs)
' CheckMessages()
MsgBox("Test me")
End Sub
End ClassI would appreciate any help that anyone can give me!
Thanks,
Jason Gaylord
jgaylord@aspalliance.com

Timer Issue
Christopher Gordon
agthomas
Nikhil Acharya
Thanks for the quick response. I tried what you said. Here is my code:Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Configuration
Imports System.Windows.Forms
Imports System.IO
Imports System.Data
Public Class Alert
Inherits System.Windows.Forms.Form
'Private Timer1 As System.Timers.Timer
Public Sub New()
MyBase.New()
InitializeComponent()
Try
Timer1.Interval = Convert.ToDouble(ConfigurationSettings.AppSettings("CheckInterval"))
Catch
End Try
Me.Hide()
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
Friend WithEvents timer1 As System.Timers.Timer
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Alert))
Me.Timer1 = New System.Timers.Timer()
'AddHandler Timer1.Elapsed, AddressOf timer1_Elapsed
Me.Timer1.BeginInit()
'
'Timer1
'
Me.Timer1.Enabled = True
Me.Timer1.Interval = 4000
Me.Timer1.SynchronizingObject = Me
'
'Alert
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(144, 54)
Me.ControlBox = False
Me.Enabled = False
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.Name = "Alert"
Me.ShowInTaskbar = True
Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual
Me.Text = "HelpDesk Alert"
Me.WindowState = System.Windows.Forms.FormWindowState.Minimized
End Sub
Private Sub timer1_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles timer1.Elapsed
MsgBox("Test me")
End Sub
End Class<b>It still doesn't work.</b> Have any other ideas Again, thanks for the help!
todong
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
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
'Required by the Windows Form Designer
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()
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
'
'Timer1
'
Me.Timer1.Interval = 4000
'
'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
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
MessageBox.Show("Boom!")
End Sub
End Class
markdrury
The most important issue is the setting of the SynchronizingObject property--if you attempt to modify the form or its contents from the Elapsed event and you haven't set that to be some object that's in the same thread as the thread that created the form, you'll sooner or later run into trouble. Dragging the component from the toolbox onto the form takes care of this for you.
ctclark1
Did you look at the VS.NET help ms-help://MS.VSCC/MS.MSDNQTR.2003JAN.1033/cpref/html/frlrfsystemtimerstimerclasstopic.htm
ChrisEvans
Thanks again for the help! :)
DivideByNought
Thanks for your help. I did look at the VS.Net help already. I still can't get it to work using that namespace. Don't know why. If you come up with anything, please let me know.
Thanks again
Jason
RithuSasi
linearkieran
<configuration>
<appSettings>
<add key="CheckInterval" value="10000" />
</appSettings>
</configuration>
RichB2005