I need every 5 minutes to refresh a ListView
that is
loaded with a table, it works the first time but it does not work
if there is still inactivity. I have tried several things without success.
Imports System.Runtime.InteropServices
Public Class Principal
Private Structure LASTINPUTINFO
Public cbSize As UInteger
Public dwTime As UInteger
End Structure
<DllImport("User32.dll")>
Private Shared Function GetLastInputInfo(ByRef plii As LASTINPUTINFO) As Boolean
End Function
Public Function GetInactiveTime() As Nullable(Of TimeSpan)
Dim info As LASTINPUTINFO = New LASTINPUTINFO
info.cbSize = CUInt(Marshal.SizeOf(info))
If (GetLastInputInfo(info)) Then
Return TimeSpan.FromMilliseconds(Environment.TickCount - info.dwTime)
Else
Return Nothing
End If
End Function
Private Sub Principal_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer2.Start()
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
Dim inactiveTime = GetInactiveTime()
If (inactiveTime Is Nothing) Then
Label5.Text = "Desconocido"
ElseIf (inactiveTime.Value.TotalSeconds > 300) Then
Label5.Text = String.Format("Inactivo por {0}segundos ",
inactiveTime.Value.TotalSeconds.ToString("#"))
Limpiar_lista(Listview1)
Mostrar_Lista(Listview1)
Else
Label5.Text = "Aplicacion Activa"
End If
End Sub
End Class