Your simplest solution would be to use a Timer and set the Duration property to the number of milliseconds you'd like in your timeout. Whenever you encounter activity, you can just reset the timer by calling Stop then immediately calling Start. Place whatever code you'd like in the Timer's Tick event (assuming this is a
System.Windows.Forms.Timer
) and you'll be all set.
(Source : Stack Overflow)