Windows Forms + System.Threading

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am working on a program where I need 2 things to happen at the same time.
The form needs to load and at the same time I want to start a timer which
after a certain amount of time kills the entire application. The user has to
click submit on the form within 2 minutes, or else I want something else to
happen. For example, lets say I want a form to open and say the computer is
going to logoff in 2 minutes. The user can select logoff now, or the user
can ignore the form, in which case the form logs off after 2 minutes. I have
tried using the System.Threading.Timers, with the Wait.Any method, but I
don't seem to be able to use that with Application.Run, which causes one of
the two things to happen but not both at the same time. Does anyone have any
suggestions?
 
If this is just timer, kick it off during form load and handle tick event in
the form code. You can always use Close method to close the form.
If it is "something else" then kick off another thread - again during form
load and have some form event ready to handle completion of that
"something". You can use BackgroundWorker and it's RunWorkerCompleted event
to handle completion of submitted thread.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top