I've written a C# Windows Forms application. Now I've decided that it
needs to check that the user is a member of certain groups as it's
opening and close if they're not. A bit of research suggests that I
won't be able to close the application before it's finished loading.
this.Close() doesn't work in these situations. What's the recognized
way of achieving this?
I like to do things properly. If I was starting from scratch, would I
create the project as a Console Project and use something like:
Form1 form1 = new Form1();
form1.ShowDialog();
to display the form? (And find some way to hide the Console window.)
Or do I create it as a Windows Application and find run the group
membership checks as part of the first (somehow hidden) window and then
call the main window with code similar to that above?
Simon
Chris Dunaway - 12 Aug 2005 15:21 GMT
Can't you do it in your Main method?
[STAThread]
static void Main()
{
bool isMember;
//Code to check group membership here
if (isMember)
Application.Run(new Form1());
else
MessageBox.Show("You're not a member!");
}
Jakob Christensen - 12 Aug 2005 15:39 GMT
You can perforam the check in the Main function of your app before the call
to Application.Run and then neglect to call Application.Run if the check
fails. This will cause the application to exit without ever showing the form.
HTH, Jakob.

Signature
http://www.dotninjas.dk
http://www.powerbytes.dk
> I've written a C# Windows Forms application. Now I've decided that it
> needs to check that the user is a member of certain groups as it's
[quoted text clipped - 14 lines]
>
> Simon