Here is the exact code:
autoCloseTimer.Elapsed += (sender, eventArgs) => {
this.Invoke(new System.Action<System.Windows.Forms.Form>((param) => { param.Close(); }), box);
};
The call to Invoke should be done on any Control actually working in your UI; in your case this is your form referenced via the parameter "
this
".
If by some reason you use C# v.2, you should add declaration of
Action
and replace lambda syntax with anonymous delegate syntax without type inference:
delegate void Action(System.Windows.Forms.Form box);
void CloseBox(System.Windows.Forms.Form box) { box.Close();}
autoCloseTimer.Elapsed += delegate(object sender, System.Timers.ElapsedEventArgs eventArgs) {
this.Invoke(new Action(CloseBox), box);
};
I assumed
box
is a form, too. If not, just replace its type to the right one in
Action
and
CloseBox
.
—SA