Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / August 2005

Tip: Looking for answers? Try searching our database.

Closing an application before it's opened.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ssg31415926 - 12 Aug 2005 13:40 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.