Q:

Set a timeout waiting for userinput

I have a C# .NET 3.5 app that prompts for a username and a PIN.   I'd like the app to automatically reset if no PIN is entered for x seconds.   If a key is pressed within x seconds, then the timer should reset to 0 and start again.   I've searched around and found various methods for doing this, using a timer, thread.wait, but I haven't found something that was an example of what I'm trying to accomplish.  I think the solution will involve using multiple threads, but I've never had to do this before so I'm not sure where to start on this. 

A:

Doesn't need to be that clever this, unless it's a behaviour you are going to reuse a lot. 
Assuming you are showing this form modally
Put a timer on your form (disabled)
enable when the form is shown. 
Add keydown/keypress eventhandlers to the boxes that could have focus
In them restart the timer
If the timer event fires close the form returning a suitable DialogResult Cancel should do it. 
Seeing as you reset on keypress, little point in having another thread.  If you weren't resetting then M Patel's answer is the way to go, unless you want to reinvent a lot of wheels

