Does WinForm automatically close after expiration?

In Framework 4.0, I have WinForm that opens from another form, displays some things and a progress bar, and then sits there. I would like to close this pop up form after n secods if the user does not close it manually. What is the smartest way to do this?

Thank.

+5
source share
1 answer

Start the timer at the required interval, and then when it is marked for the first time, close the form. Something like that

private Timer _timer;

public PopupForm()
{
   InitializeComponent();
   _timer = new Timer();
   _timer.Interval = 5000; // interval in milliseconds here.
   _timer.Tick += (s, e) => this.Close();
   _timer.Start();
}

In fact, the smartest way would probably put this in its own StartCountdown () method, which takes time as a parameter. Logic, as usual, should not be strictly stated in the constructor ...

+9

All Articles