Hi All,
I have a simple application that allows users to clock in and out and stores
the data for use by the payroll department. It spends most of its life as a
tray icon and when the user clicks on it, a clock-in/out form is displayed.
My problem is this:
I've added a timer to the main module to allow the user to set a time to be
reminded that they should clock back in/out. The timer works great (i.e. if
it's set to remind you at 5pm, it reminds you at 5pm), but when the elapsed
event fires and the clock-in/out form is displayed, the form elements don't
repaint themselves (it's just a frame with no components) and if you click
anywhere in the form, you get the windows error message that "the application
has stopped responding."
Here's the weird thing: The sub that I use to display the form after the
timer elapses is the same sub that I call when the user right-clicks the tray
icon and selects "Display Timeclock Form" and it works like a charm. I can
open and close the form all day long with the tray icon context menu, but
when I use the timer to display the form, it freezes.
Here's what I've got... simplified. Any insights would be greatly
appreciated!
Thanks!
Mike E.
Sub main()
reminderTimer = New Timer
reminderTimer.A utoReset = False
frmMain = New frmTimeTracker
'setup context menu
cMenu.MenuItems .Add("Open Time Tracker", AddressOf cMenu_Click)
cMenu.MenuItems .Add("Set / Reset Reminder Time", AddressOf
cMenu_Click)
cMenu.MenuItems .Add("Exit Time Tracker", AddressOf cMenu_Click)
'create tray icon
trayIcon.Text = Time Tracker"
trayIcon.Icon = frmMain.Icon
trayIcon.Visibl e = True
trayIcon.Contex tMenu = cMenu
AddHandler reminderTimer.E lapsed, AddressOf OnTimerElapsed
Application.Run ()
End Sub
Public Sub OnTimerElapsed( ByVal source As Object, ByVal e As
ElapsedEventArg s)
bReminderSet = False
reminderTimer.E nabled = False
reminderTimer.C lose()
ShowTimecardFor m()
End Sub
Private Sub ShowTimecardFor m()
If (frmMain Is Nothing OrElse frmMain.IsDispo sed) Then
frmMain = New frmTimeTracker
End If
frmMain.Show()
frmMain.txtPass word.Focus()
Application.DoE vents()
End Sub 7 2679
It sounds like a threading issue. You really can't tell becuase you didn't
post the suspect code block. Is the timer handler in a different thread than
the displayed form? Did you use a delegate? I'm just guessing...
"Mike Eaton" <Mi*******@disc ussions.microso ft.com> wrote in message
news:E7******** *************** ***********@mic rosoft.com... Hi All,
I have a simple application that allows users to clock in and out and stores the data for use by the payroll department. It spends most of its life as a tray icon and when the user clicks on it, a clock-in/out form is displayed. My problem is this:
I've added a timer to the main module to allow the user to set a time to be reminded that they should clock back in/out. The timer works great (i.e. if it's set to remind you at 5pm, it reminds you at 5pm), but when the elapsed event fires and the clock-in/out form is displayed, the form elements don't repaint themselves (it's just a frame with no components) and if you click anywhere in the form, you get the windows error message that "the application has stopped responding."
Here's the weird thing: The sub that I use to display the form after the timer elapses is the same sub that I call when the user right-clicks the tray icon and selects "Display Timeclock Form" and it works like a charm. I can open and close the form all day long with the tray icon context menu, but when I use the timer to display the form, it freezes.
Here's what I've got... simplified. Any insights would be greatly appreciated!
Thanks! Mike E.
Sub main()
reminderTimer = New Timer reminderTimer.A utoReset = False
frmMain = New frmTimeTracker
'setup context menu cMenu.MenuItems .Add("Open Time Tracker", AddressOf cMenu_Click) cMenu.MenuItems .Add("Set / Reset Reminder Time", AddressOf cMenu_Click) cMenu.MenuItems .Add("Exit Time Tracker", AddressOf cMenu_Click)
'create tray icon trayIcon.Text = Time Tracker" trayIcon.Icon = frmMain.Icon trayIcon.Visibl e = True trayIcon.Contex tMenu = cMenu
AddHandler reminderTimer.E lapsed, AddressOf OnTimerElapsed
Application.Run ()
End Sub
Public Sub OnTimerElapsed( ByVal source As Object, ByVal e As ElapsedEventArg s) bReminderSet = False reminderTimer.E nabled = False reminderTimer.C lose() ShowTimecardFor m()
End Sub
Private Sub ShowTimecardFor m() If (frmMain Is Nothing OrElse frmMain.IsDispo sed) Then frmMain = New frmTimeTracker End If frmMain.Show() frmMain.txtPass word.Focus() Application.DoE vents() End Sub
Try this:
Application.Run (frmMain)
"Mike Eaton" <Mi*******@disc ussions.microso ft.com> wrote in message
news:69******** *************** ***********@mic rosoft.com... Hi Jared,
I didn't set up an explicit thread for the timer, as I was just using Application.run to control the app. The timer handler is the OnTimerElapse method in the main module. Here's the rest of the code from the main module- hopefully it will help:
Private Sub trayIcon_Double Click(ByVal sender As Object, ByVal e As System.EventArg s) Handles trayIcon.Double Click ShowTimecardFor m() End Sub
Private Sub cMenu_Click(ByV al sender As Object, ByVal e As EventArgs) Try Dim mi As MenuItem = DirectCast(send er, MenuItem) Select Case (mi.Text) Case "Open Time Tracker" ShowTimecardFor m() Case "Set / Reset Reminder Time" PromptReminder( ) Case "Exit Time Tracker" Application.Exi t() End Select Catch ice As InvalidCastExce ption ErrorMessageToF ile("Error in cMenu_Click: " + vbCrLf + ice.ToString) End Try
End Sub
Public Sub PromptReminder( ) Dim Reminder As ReminderFrm = New ReminderFrm
reminderTimer.E nabled = False
Reminder.ShowDi alog() If (Reminder.Dialo gResult = DialogResult.OK ) Then ReminderTime = Reminder.cboTim es.Text.ToStrin g() Dim ts As TimeSpan ts = Date.Parse(Remi nderTime).Subtr act(Now) If (ts.TotalMillis econds < 1) Then Exit Sub End If reminderTimer.I nterval = ts.TotalMillise conds bReminderSet = True reminderTimer.E nabled = True Else 'reminder cancelled End If End Sub
"Jared" wrote:
It sounds like a threading issue. You really can't tell becuase you didn't post the suspect code block. Is the timer handler in a different thread than the displayed form? Did you use a delegate? I'm just guessing...
"Mike Eaton" <Mi*******@disc ussions.microso ft.com> wrote in message news:E7******** *************** ***********@mic rosoft.com... > Hi All, > > I have a simple application that allows users to clock in and out and > stores > the data for use by the payroll department. It spends most of its life > as > a > tray icon and when the user clicks on it, a clock-in/out form is > displayed. > My problem is this: > > I've added a timer to the main module to allow the user to set a time > to > be > reminded that they should clock back in/out. The timer works great > (i.e. > if > it's set to remind you at 5pm, it reminds you at 5pm), but when the > elapsed > event fires and the clock-in/out form is displayed, the form elements > don't > repaint themselves (it's just a frame with no components) and if you > click > anywhere in the form, you get the windows error message that "the > application > has stopped responding." > > Here's the weird thing: The sub that I use to display the form after > the > timer elapses is the same sub that I call when the user right-clicks > the > tray > icon and selects "Display Timeclock Form" and it works like a charm. I > can > open and close the form all day long with the tray icon context menu, > but > when I use the timer to display the form, it freezes. > > Here's what I've got... simplified. Any insights would be greatly > appreciated! > > Thanks! > Mike E. > > Sub main() > > reminderTimer = New Timer > reminderTimer.A utoReset = False > > frmMain = New frmTimeTracker > > 'setup context menu > cMenu.MenuItems .Add("Open Time Tracker", AddressOf cMenu_Click) > cMenu.MenuItems .Add("Set / Reset Reminder Time", AddressOf > cMenu_Click) > cMenu.MenuItems .Add("Exit Time Tracker", AddressOf cMenu_Click) > > 'create tray icon > trayIcon.Text = Time Tracker" > trayIcon.Icon = frmMain.Icon > trayIcon.Visibl e = True > trayIcon.Contex tMenu = cMenu > > AddHandler reminderTimer.E lapsed, AddressOf OnTimerElapsed > > Application.Run () > > End Sub > > > Public Sub OnTimerElapsed( ByVal source As Object, ByVal e As > ElapsedEventArg s) > bReminderSet = False > reminderTimer.E nabled = False > reminderTimer.C lose() > ShowTimecardFor m() > > End Sub > > Private Sub ShowTimecardFor m() > If (frmMain Is Nothing OrElse frmMain.IsDispo sed) Then > frmMain = New frmTimeTracker > End If > frmMain.Show() > frmMain.txtPass word.Focus() > Application.DoE vents() > End Sub > >
I don't see how that would make a difference (could be my inexperience
talking), the documentation states that application.run will start a message
loop on the current thread, whereas application.run (frmMain) does the exact
same thing, except it initially displays a form.
The documentation on DoEvents also states:
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003 FEB.1033/cpref/html/frlrfsystemwind owsformsapplica tionclassdoeven tstopic.htm
CAUTION Calling this method can cause code to be re-entered if a message
raises an event.
I am assuming you placed the DoEvents in your code after you started having
problems in order to repaint your form.
You are also using a System.Timers.T imer and not a
System.Windows. Forms.Timer, read the overviews of each they define the
idiosyncrasies of each control. It seems like the system.timers.t imer is
meant for multi-threaded apps and the system.windows. forms.timer is meant
for use in sta windows apps such as this one.
As a suggestion, I would dispose of my forms when done, and create a new
instance when the user requests it (if the overhead isn't too great, etc.)
especially if there may be several hours in between uses. I have a post in
microsoft.publi c.dotnet.langua ges.vb.controls titled "vb.net browser
refreshing" dated on 9.10.2004 that show an example of using a few api calls
to set the forms focus. It may come in handy when you are displaying your
reminders.
"Think_Fast " <nospam@haha> wrote in message
news:10******** *****@corp.supe rnews.com... Try this:
Application.Run (frmMain)
"Mike Eaton" <Mi*******@disc ussions.microso ft.com> wrote in message news:69******** *************** ***********@mic rosoft.com... Hi Jared,
I didn't set up an explicit thread for the timer, as I was just using Application.run to control the app. The timer handler is the OnTimerElapse method in the main module. Here's the rest of the code from the main module- hopefully it will help:
Private Sub trayIcon_Double Click(ByVal sender As Object, ByVal e As System.EventArg s) Handles trayIcon.Double Click ShowTimecardFor m() End Sub
Private Sub cMenu_Click(ByV al sender As Object, ByVal e As EventArgs) Try Dim mi As MenuItem = DirectCast(send er, MenuItem) Select Case (mi.Text) Case "Open Time Tracker" ShowTimecardFor m() Case "Set / Reset Reminder Time" PromptReminder( ) Case "Exit Time Tracker" Application.Exi t() End Select Catch ice As InvalidCastExce ption ErrorMessageToF ile("Error in cMenu_Click: " + vbCrLf + ice.ToString) End Try
End Sub
Public Sub PromptReminder( ) Dim Reminder As ReminderFrm = New ReminderFrm
reminderTimer.E nabled = False
Reminder.ShowDi alog() If (Reminder.Dialo gResult = DialogResult.OK ) Then ReminderTime = Reminder.cboTim es.Text.ToStrin g() Dim ts As TimeSpan ts = Date.Parse(Remi nderTime).Subtr act(Now) If (ts.TotalMillis econds < 1) Then Exit Sub End If reminderTimer.I nterval = ts.TotalMillise conds bReminderSet = True reminderTimer.E nabled = True Else 'reminder cancelled End If End Sub
"Jared" wrote:
It sounds like a threading issue. You really can't tell becuase you didn't post the suspect code block. Is the timer handler in a different thread than the displayed form? Did you use a delegate? I'm just guessing...
"Mike Eaton" <Mi*******@disc ussions.microso ft.com> wrote in message news:E7******** *************** ***********@mic rosoft.com... > Hi All, > > I have a simple application that allows users to clock in and out and > stores > the data for use by the payroll department. It spends most of its > life as > a > tray icon and when the user clicks on it, a clock-in/out form is > displayed. > My problem is this: > > I've added a timer to the main module to allow the user to set a time > to > be > reminded that they should clock back in/out. The timer works great > (i.e. > if > it's set to remind you at 5pm, it reminds you at 5pm), but when the > elapsed > event fires and the clock-in/out form is displayed, the form elements > don't > repaint themselves (it's just a frame with no components) and if you > click > anywhere in the form, you get the windows error message that "the > application > has stopped responding." > > Here's the weird thing: The sub that I use to display the form after > the > timer elapses is the same sub that I call when the user right-clicks > the > tray > icon and selects "Display Timeclock Form" and it works like a charm. > I > can > open and close the form all day long with the tray icon context menu, > but > when I use the timer to display the form, it freezes. > > Here's what I've got... simplified. Any insights would be greatly > appreciated! > > Thanks! > Mike E. > > Sub main() > > reminderTimer = New Timer > reminderTimer.A utoReset = False > > frmMain = New frmTimeTracker > > 'setup context menu > cMenu.MenuItems .Add("Open Time Tracker", AddressOf cMenu_Click) > cMenu.MenuItems .Add("Set / Reset Reminder Time", AddressOf > cMenu_Click) > cMenu.MenuItems .Add("Exit Time Tracker", AddressOf cMenu_Click) > > 'create tray icon > trayIcon.Text = Time Tracker" > trayIcon.Icon = frmMain.Icon > trayIcon.Visibl e = True > trayIcon.Contex tMenu = cMenu > > AddHandler reminderTimer.E lapsed, AddressOf OnTimerElapsed > > Application.Run () > > End Sub > > > Public Sub OnTimerElapsed( ByVal source As Object, ByVal e As > ElapsedEventArg s) > bReminderSet = False > reminderTimer.E nabled = False > reminderTimer.C lose() > ShowTimecardFor m() > > End Sub > > Private Sub ShowTimecardFor m() > If (frmMain Is Nothing OrElse frmMain.IsDispo sed) Then > frmMain = New frmTimeTracker > End If > frmMain.Show() > frmMain.txtPass word.Focus() > Application.DoE vents() > End Sub > >
Forgot a couple of things. First make the form invisible.
frmMain.Visible =False
Application.Run (frmMain)
And put this in your closing event of your form otherwise the application
will terminate
Private Sub frmTimeTracker_ Closing(ByVal sender As Object, ByVal e As
System.Componen tModel.CancelEv entArgs) Handles MyBase.Closing
Me.Visible = False
e.Cancel = True
End Sub
"Think_Fast " <nospam@haha> wrote in message
news:10******** *****@corp.supe rnews.com... Try this:
Application.Run (frmMain)
"Mike Eaton" <Mi*******@disc ussions.microso ft.com> wrote in message news:69******** *************** ***********@mic rosoft.com... Hi Jared,
I didn't set up an explicit thread for the timer, as I was just using Application.run to control the app. The timer handler is the OnTimerElapse method in the main module. Here's the rest of the code from the main module- hopefully it will help:
Private Sub trayIcon_Double Click(ByVal sender As Object, ByVal e As System.EventArg s) Handles trayIcon.Double Click ShowTimecardFor m() End Sub
Private Sub cMenu_Click(ByV al sender As Object, ByVal e As EventArgs) Try Dim mi As MenuItem = DirectCast(send er, MenuItem) Select Case (mi.Text) Case "Open Time Tracker" ShowTimecardFor m() Case "Set / Reset Reminder Time" PromptReminder( ) Case "Exit Time Tracker" Application.Exi t() End Select Catch ice As InvalidCastExce ption ErrorMessageToF ile("Error in cMenu_Click: " + vbCrLf + ice.ToString) End Try
End Sub
Public Sub PromptReminder( ) Dim Reminder As ReminderFrm = New ReminderFrm
reminderTimer.E nabled = False
Reminder.ShowDi alog() If (Reminder.Dialo gResult = DialogResult.OK ) Then ReminderTime = Reminder.cboTim es.Text.ToStrin g() Dim ts As TimeSpan ts = Date.Parse(Remi nderTime).Subtr act(Now) If (ts.TotalMillis econds < 1) Then Exit Sub End If reminderTimer.I nterval = ts.TotalMillise conds bReminderSet = True reminderTimer.E nabled = True Else 'reminder cancelled End If End Sub
"Jared" wrote:
It sounds like a threading issue. You really can't tell becuase you didn't post the suspect code block. Is the timer handler in a different thread than the displayed form? Did you use a delegate? I'm just guessing...
"Mike Eaton" <Mi*******@disc ussions.microso ft.com> wrote in message news:E7******** *************** ***********@mic rosoft.com... > Hi All, > > I have a simple application that allows users to clock in and out and > stores > the data for use by the payroll department. It spends most of its > life as > a > tray icon and when the user clicks on it, a clock-in/out form is > displayed. > My problem is this: > > I've added a timer to the main module to allow the user to set a time > to > be > reminded that they should clock back in/out. The timer works great > (i.e. > if > it's set to remind you at 5pm, it reminds you at 5pm), but when the > elapsed > event fires and the clock-in/out form is displayed, the form elements > don't > repaint themselves (it's just a frame with no components) and if you > click > anywhere in the form, you get the windows error message that "the > application > has stopped responding." > > Here's the weird thing: The sub that I use to display the form after > the > timer elapses is the same sub that I call when the user right-clicks > the > tray > icon and selects "Display Timeclock Form" and it works like a charm. > I > can > open and close the form all day long with the tray icon context menu, > but > when I use the timer to display the form, it freezes. > > Here's what I've got... simplified. Any insights would be greatly > appreciated! > > Thanks! > Mike E. > > Sub main() > > reminderTimer = New Timer > reminderTimer.A utoReset = False > > frmMain = New frmTimeTracker > > 'setup context menu > cMenu.MenuItems .Add("Open Time Tracker", AddressOf cMenu_Click) > cMenu.MenuItems .Add("Set / Reset Reminder Time", AddressOf > cMenu_Click) > cMenu.MenuItems .Add("Exit Time Tracker", AddressOf cMenu_Click) > > 'create tray icon > trayIcon.Text = Time Tracker" > trayIcon.Icon = frmMain.Icon > trayIcon.Visibl e = True > trayIcon.Contex tMenu = cMenu > > AddHandler reminderTimer.E lapsed, AddressOf OnTimerElapsed > > Application.Run () > > End Sub > > > Public Sub OnTimerElapsed( ByVal source As Object, ByVal e As > ElapsedEventArg s) > bReminderSet = False > reminderTimer.E nabled = False > reminderTimer.C lose() > ShowTimecardFor m() > > End Sub > > Private Sub ShowTimecardFor m() > If (frmMain Is Nothing OrElse frmMain.IsDispo sed) Then > frmMain = New frmTimeTracker > End If > frmMain.Show() > frmMain.txtPass word.Focus() > Application.DoE vents() > End Sub > >
Mike,
When I see it right in your code, than you are creating everytime a new form
from the same class, try to work with visible true and false or something
like that and use the object you are in.
You can not instance an object as new and delete it in the same time the one
which is instancing it.
When I see it right you do now something as
frmmain
new frmmain
new frmmain
new frmmain
new frmmain
I hope this helps?
Cor
Hi Jared,
I didn't set up an explicit thread for the timer, as I was just using
Application.run to control the app. The timer handler is the OnTimerElapse
method in the main module. Here's the rest of the code from the main module-
hopefully it will help:
Private Sub trayIcon_Double Click(ByVal sender As Object, ByVal e As
System.EventArg s) Handles trayIcon.Double Click
ShowTimecardFor m()
End Sub
Private Sub cMenu_Click(ByV al sender As Object, ByVal e As EventArgs)
Try
Dim mi As MenuItem = DirectCast(send er, MenuItem)
Select Case (mi.Text)
Case "Open Time Tracker"
ShowTimecardFor m()
Case "Set / Reset Reminder Time"
PromptReminder( )
Case "Exit Time Tracker"
Application.Exi t()
End Select
Catch ice As InvalidCastExce ption
ErrorMessageToF ile("Error in cMenu_Click: " + vbCrLf +
ice.ToString)
End Try
End Sub
Public Sub PromptReminder( )
Dim Reminder As ReminderFrm = New ReminderFrm
reminderTimer.E nabled = False
Reminder.ShowDi alog()
If (Reminder.Dialo gResult = DialogResult.OK ) Then
ReminderTime = Reminder.cboTim es.Text.ToStrin g()
Dim ts As TimeSpan
ts = Date.Parse(Remi nderTime).Subtr act(Now)
If (ts.TotalMillis econds < 1) Then
Exit Sub
End If
reminderTimer.I nterval = ts.TotalMillise conds
bReminderSet = True
reminderTimer.E nabled = True
Else
'reminder cancelled
End If
End Sub
"Jared" wrote: It sounds like a threading issue. You really can't tell becuase you didn't post the suspect code block. Is the timer handler in a different thread than the displayed form? Did you use a delegate? I'm just guessing...
"Mike Eaton" <Mi*******@disc ussions.microso ft.com> wrote in message news:E7******** *************** ***********@mic rosoft.com... Hi All,
I have a simple application that allows users to clock in and out and stores the data for use by the payroll department. It spends most of its life as a tray icon and when the user clicks on it, a clock-in/out form is displayed. My problem is this:
I've added a timer to the main module to allow the user to set a time to be reminded that they should clock back in/out. The timer works great (i.e. if it's set to remind you at 5pm, it reminds you at 5pm), but when the elapsed event fires and the clock-in/out form is displayed, the form elements don't repaint themselves (it's just a frame with no components) and if you click anywhere in the form, you get the windows error message that "the application has stopped responding."
Here's the weird thing: The sub that I use to display the form after the timer elapses is the same sub that I call when the user right-clicks the tray icon and selects "Display Timeclock Form" and it works like a charm. I can open and close the form all day long with the tray icon context menu, but when I use the timer to display the form, it freezes.
Here's what I've got... simplified. Any insights would be greatly appreciated!
Thanks! Mike E.
Sub main()
reminderTimer = New Timer reminderTimer.A utoReset = False
frmMain = New frmTimeTracker
'setup context menu cMenu.MenuItems .Add("Open Time Tracker", AddressOf cMenu_Click) cMenu.MenuItems .Add("Set / Reset Reminder Time", AddressOf cMenu_Click) cMenu.MenuItems .Add("Exit Time Tracker", AddressOf cMenu_Click)
'create tray icon trayIcon.Text = Time Tracker" trayIcon.Icon = frmMain.Icon trayIcon.Visibl e = True trayIcon.Contex tMenu = cMenu
AddHandler reminderTimer.E lapsed, AddressOf OnTimerElapsed
Application.Run ()
End Sub
Public Sub OnTimerElapsed( ByVal source As Object, ByVal e As ElapsedEventArg s) bReminderSet = False reminderTimer.E nabled = False reminderTimer.C lose() ShowTimecardFor m()
End Sub
Private Sub ShowTimecardFor m() If (frmMain Is Nothing OrElse frmMain.IsDispo sed) Then frmMain = New frmTimeTracker End If frmMain.Show() frmMain.txtPass word.Focus() Application.DoE vents() End Sub
Hi Jared,
I didn't set up an explicit thread for the timer, as I was just using
Application.run to control the app. The timer handler is the OnTimerElapse
method in the main module. Here's the rest of the code from the main module-
hopefully it will help:
Private Sub trayIcon_Double Click(ByVal sender As Object, ByVal e As
System.EventArg s) Handles trayIcon.Double Click
ShowTimecardFor m()
End Sub
Private Sub cMenu_Click(ByV al sender As Object, ByVal e As EventArgs)
Try
Dim mi As MenuItem = DirectCast(send er, MenuItem)
Select Case (mi.Text)
Case "Open Time Tracker"
ShowTimecardFor m()
Case "Set / Reset Reminder Time"
PromptReminder( )
Case "Exit Time Tracker"
Application.Exi t()
End Select
Catch ice As InvalidCastExce ption
ErrorMessageToF ile("Error in cMenu_Click: " + vbCrLf +
ice.ToString)
End Try
End Sub
Public Sub PromptReminder( )
Dim Reminder As ReminderFrm = New ReminderFrm
reminderTimer.E nabled = False
Reminder.ShowDi alog()
If (Reminder.Dialo gResult = DialogResult.OK ) Then
ReminderTime = Reminder.cboTim es.Text.ToStrin g()
Dim ts As TimeSpan
ts = Date.Parse(Remi nderTime).Subtr act(Now)
If (ts.TotalMillis econds < 1) Then
Exit Sub
End If
reminderTimer.I nterval = ts.TotalMillise conds
bReminderSet = True
reminderTimer.E nabled = True
Else
'reminder cancelled
End If
End Sub
"Jared" wrote: It sounds like a threading issue. You really can't tell becuase you didn't post the suspect code block. Is the timer handler in a different thread than the displayed form? Did you use a delegate? I'm just guessing...
"Mike Eaton" <Mi*******@disc ussions.microso ft.com> wrote in message news:E7******** *************** ***********@mic rosoft.com... Hi All,
I have a simple application that allows users to clock in and out and stores the data for use by the payroll department. It spends most of its life as a tray icon and when the user clicks on it, a clock-in/out form is displayed. My problem is this:
I've added a timer to the main module to allow the user to set a time to be reminded that they should clock back in/out. The timer works great (i.e. if it's set to remind you at 5pm, it reminds you at 5pm), but when the elapsed event fires and the clock-in/out form is displayed, the form elements don't repaint themselves (it's just a frame with no components) and if you click anywhere in the form, you get the windows error message that "the application has stopped responding."
Here's the weird thing: The sub that I use to display the form after the timer elapses is the same sub that I call when the user right-clicks the tray icon and selects "Display Timeclock Form" and it works like a charm. I can open and close the form all day long with the tray icon context menu, but when I use the timer to display the form, it freezes.
Here's what I've got... simplified. Any insights would be greatly appreciated!
Thanks! Mike E.
Sub main()
reminderTimer = New Timer reminderTimer.A utoReset = False
frmMain = New frmTimeTracker
'setup context menu cMenu.MenuItems .Add("Open Time Tracker", AddressOf cMenu_Click) cMenu.MenuItems .Add("Set / Reset Reminder Time", AddressOf cMenu_Click) cMenu.MenuItems .Add("Exit Time Tracker", AddressOf cMenu_Click)
'create tray icon trayIcon.Text = Time Tracker" trayIcon.Icon = frmMain.Icon trayIcon.Visibl e = True trayIcon.Contex tMenu = cMenu
AddHandler reminderTimer.E lapsed, AddressOf OnTimerElapsed
Application.Run ()
End Sub
Public Sub OnTimerElapsed( ByVal source As Object, ByVal e As ElapsedEventArg s) bReminderSet = False reminderTimer.E nabled = False reminderTimer.C lose() ShowTimecardFor m()
End Sub
Private Sub ShowTimecardFor m() If (frmMain Is Nothing OrElse frmMain.IsDispo sed) Then frmMain = New frmTimeTracker End If frmMain.Show() frmMain.txtPass word.Focus() Application.DoE vents() End Sub
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: rhaley |
last post by:
ugh. Okay, I need to figure out the number of milliseconds between
DateTime.Now and the end of the day so that I can make changes based on
the date roll-over. I need to implement a Timer so that I can process
things on the Timer.Elapsed event that would happen right at the date
change (unless there is a better suggestion to implement an event on
the date change). DateTime isn't so friendly to this calculation.
Please, any suggestions are...
|
by: Besta |
last post by:
Hello all,
I am having trouble creating a windows service with a timer.
Everything seems to go ok but the elapsed event does not fire.Can
anyone shed any light on this, may be something simple as I am new to
this. Full code below :
using System;
using System.Collections;
using System.ComponentModel;
|
by: Philip Wagenaar |
last post by:
Hello,
I am using a timer object in my Windows Forms Application. Does the code in
..elapsed event run in a diffrent thread? If the interval is set to 10
milliseconds and the time to execute the code in the .elapsed event takes 1
secocond to complete, what happens?
1) Timer starts. 10 milliseconds later the code is executed and timer stops.
When code is done, 1 seconds later, the timer continues. 10 milliseconds
later the code is...
|
by: Liverpool fan |
last post by:
I have a windows application written using VB .NET that encompasses a
countdown timer modal dialog. The timer is a System.Timers.Timer with
an interval of 1 second. AutoReset is not set so accepts the default of
True. The Elapsed event handler updates the dialog box with how long
before it will close, acting as a timer itself. The dialog has a time
to close property which is checked every time the Elapsed event fires.
The problem I have...
|
by: martin1 |
last post by:
All,
is there window form refresh property? I try to set up window form refresh
per minute. Thanks
| |
by: Gina_Marano |
last post by:
I have created an array of timers (1-n). At first I just created
windows form timers but I read that system timers are better for
background work. The timers will just be monitoring different
directories and updating a database. No interaction with the GUI.
Problem is that the system timers do not have a tag property so I can
tie in an object.
example (old way):
|
by: Tony Gravagno |
last post by:
I have a class that instantiates two Timer objects that fire at
different intervals. My class can be instantiated within a Windows
Form or from a Windows Service. Actions performed by one of the event
handlers may take longer than the interval for either of the timers,
so it's possible for multiple events to fire "simultaneously" and for
events to queue up. I'm attempting to get the timers to sync on some
reference type object, or use...
|
by: igor |
last post by:
I have recently discovered that the system.Timers.Timer from.Net
Framework v1.1 is not reliable when used on Windows 2003 server. When
incorporated into a Windows Service, the timer_elapsed event will stop
executing after 30 to 40 days. After learning this, I found the same
issue had been documented in the the System.Threading.Timer class as
well. This limits my options for having a timer based windows service
using the .net framework....
|
by: Boki |
last post by:
Hi All,
I have a timer, if my data queue Q has data, the timer should start
work, if there is no data in Q, the timer should stop.
However, there is an event can fire timer to start.
Should I add a variable to know how many records inside Q ?
Ya, I think so, because timer should use for unknown events, check it
in a period.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |