What if user runs the application without moving the mouse, I mean with keyboard
Arjun Paudel
One Example, One Form and paste the following code
Public Class Form1
Dim st As New Stopwatch
Private WithEvents bw As New System.ComponentModel.BackgroundWorker
Private UsingAgain As Boolean = False
Private SecondToWaitFor As Integer = 5
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.KeyPreview = True
bw.WorkerSupportsCancellation = True
AddHandler Application.Idle, AddressOf Application_Idle
st.Start()
End Sub
Private Sub Application_Idle()
If st.Elapsed.Seconds > SecondToWaitFor AndAlso Not bw.IsBusy Then
bw.RunWorkerAsync()
End If
End Sub
Private Sub SomeLengthyTask() Handles bw.DoWork
While Not bw.CancellationPending
Debug.WriteLine("Doing Work")
Threading.Thread.Sleep(1000)
End While
End Sub
Private Sub Form1_MouseMove(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.MouseMove
st = Stopwatch.StartNew()
bw.CancelAsync()
End Sub
Private Sub Form1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
st = Stopwatch.StartNew()
bw.CancelAsync()
End Sub
End Class
Arjun Paudel