IdleTimer only countdown to 10 and reset

  • Thread starter Thread starter wk89
  • Start date Start date
W

wk89

Guest
I have a countdown time called idleTimer.
When it reaches 0, it should refresh the DataGridView.

I have a textfile called refreshInterval.txt where it's value will set the idleTimer Interval value.

refreshInterval.txt
This means the IdleTimer will start from 30 seconds and countdown every sec to 0.

30

When the Form loads, it will read the refreshInterval.txt and set the IdleTimer.

Public Shared idletick As Integer 'The Countdown refresh timer display (keep changing)
Public Shared fixedRefreshTime As Integer 'The set refresh time taken from file

Public Sub adminViewForm_Load(sender As Object, e As EventArgs) Handles Me.Load
Me.ProjectsTableAdapter.Fill(Me.EVC_ProjectsDataSet.Projects)
AddHandler System.Windows.Forms.Application.Idle, AddressOf Application_Idle

'Read refreshInterval.txt and load values into Settings
Dim FileToString As String = "" 'grab 1 line from file
Dim settingString(2) As String 'Store Substring from file to temp String()
Dim i As Integer = 0 'Array index
Dim filePath As String = "..\..\..\config\refreshInterval.txt"
Dim filenum As Integer

filenum = FreeFile()

'Read from File
Try
FileOpen(filenum, filePath, OpenMode.Input)
While Not EOF(filenum)
FileToString = LineInput(filenum)
settingString(i) = FileToString
i += 1
End While

FileClose(filenum)
Catch ex As Exception
MessageBox.Show("File Error Occurred!" + vbCrLf + ex.ToString)
End Try

'Get Value of IdleTimer.Interval from refreshInterval.txt
fixedRefreshTime = settingString(0)
IdleTimer.Interval = settingString(0) * 1000 ' Change to millisecs
idletick = IdleTimer.Interval / 1000
IdleTimer.Start()
ClockTimer.Start()


RefreshTable()
loadCellColor()
End Sub

When the idleTimer expires, it will read the refreshInterval.txt again (in case the value changes), Refresh the GridView and start countdown again.

'IdleTime expires - READ file (in case Admin change refreshTiming)
Private Sub IdleTimer_Tick(sender As Object, e As EventArgs) Handles IdleTimer.Tick
'==================================================================================================
'Read refreshInterval.txt and load values into Settings
Dim FileToString As String = "" 'grab 1 line from file
Dim settingString(2) As String 'Store Substring from file to temp String()
Dim i As Integer = 0 'Array index
Dim filePath As String = "..\..\..\config\refreshInterval.txt"
Dim filenum As Integer

filenum = FreeFile()

'Read from File
Try
FileOpen(filenum, filePath, OpenMode.Input)
While Not EOF(filenum)
FileToString = LineInput(filenum)
settingString(i) = FileToString
i += 1
End While

FileClose(filenum)
Catch ex As Exception
MessageBox.Show("File Error Occurred!" + vbCrLf + ex.ToString)
End Try

'Get Value of IdleTimer.Interval from refreshInterval.txt
fixedRefreshTime = settingString(0)
IdleTimer.Interval = settingString(0) * 1000 ' Change to millisecs
'==================================================================================================

refreshTick_Label.Text = fixedRefreshTime.ToString
idletick = fixedRefreshTime

RefreshTable()
loadCellColor()
End Sub

I have a few other Events that reset the IdleTimer. This is to allow time for user to edit the GridView.

'When Program is Idle, start Timer to refresh
Private Sub Application_Idle(ByVal sender As Object, ByVal e As EventArgs)
IdleTimer.Start()
End Sub

'Whenever keydown - reset the timer
Private Sub adminViewForm_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
refreshTick_Label.Text = fixedRefreshTime.ToString
idletick = fixedRefreshTime
IdleTimer.Stop()
End Sub

'Whenever MouseMove - reset the timer
Private Sub Panel1_MouseMove(sender As Object, e As MouseEventArgs) Handles Panel1.MouseMove
refreshTick_Label.Text = fixedRefreshTime.ToString
idletick = fixedRefreshTime
IdleTimer.Stop()
End Sub

Private Sub ProjectsDataGridView_MouseMove(sender As Object, e As MouseEventArgs) Handles ProjectsDataGridView.MouseMove
refreshTick_Label.Text = fixedRefreshTime.ToString
idletick = fixedRefreshTime
IdleTimer.Stop()
End Sub

IdleTimer properties
The INTERVAL doesn't matter, since it will be changed by the program.
1435436.jpg


Now here is the problem.
The idleTimer always countdown to 10, then jumps back to 30. Which means the idleTimer never expires.
I tried changing to 40,50,25 and it's the same thing happening.
When I set the value below 10, let's say 5, it will countdown to 0, but the TICK event didn't trigger, and it reset to 5.

Continue reading...
 

Similar threads

Back
Top