9 June 2011

C# Closing A Form In The Constructor

I had an odd need to close an application if a user failed to set some basic user data in a C# application tonight. The flow was that a very simple dialog was displayed during the main windows constructor call and if they dismissed the dialog the application was to end.

After some head scratching I found the only way to do this was with ...

this.BeginInvoke(new MethodInvoker(this.Close));

No comments: