I have a C#.net 2008 desktop application that I would like to stop before the first desktop screen shows up. I want to stop this application from executing immediately if the user has not been granted access to the application after looking up what access they have been granted by the active directory.
I want to stop the application before the following statement is executed: Application.Run(new Mainform());
i would like to stop the application from running in program.cs.
The only options that are close to what I want to do are:
Application.ExitThread(); or Application.Exit();
However these statements run after the Application.Run(new Mainform()); statement is executed.
Thus my questions are:
1. Is there way to not display the first desktop screen? If so, what would be code be?
2. If that is not possible, what are my other options? Do I just display the desktop tabs and let the user select the tabs they want to work with? if the user does not have access to that tab, do i display a message saying 'no access' and redisplay the screen like it was before the user clicked on the tab? if so, can you show me some example code?
3. If my options do not work, what do you suggest and can you point me to a reference of some code I can use?
Loading
Sam HobbsPosted Aug 29, 2011, 9:29 PM
You can even show a login form or something like that using something such as "Application.Run(new LoginForm())". The actual code would likely be more complicated than that, but that is the concept. The problem with that is that if it is ever valid to login differently, and if the login is only done at the beginning of "Main" (in the Program.cs) then the program would have to exit and be re-executed in order to do the re-login.
Note that instead of saying "Program.cs", in this context it is more appropriate to say "Main function". Then your terminology would be closer to what is actually happening. It helps for you to understand what the Main function is and such. Do you?
Sam HobbsPosted Aug 31, 2011, 2:00 PM
The important thing to understand is that the Main function is where Windows transfers control to your application. The Main function must be static in a static class, therefore there will always be one instance of the class. When Visual Studio creates a project and the type of project is for an application that is executed from Windows (projects such as class libraries and Silverlight are not) it generates a class named "Program" and therefore the file it is in is called "Program.cs". It is possible to put other classes into the Program.cs file. So it is more appropriate to say "Program class" than "Program.cs", unless you are referring to a class or classes in Program.cs that are not the Program class, in which aces you would refer to the other class(es) by their name.
jasminiePosted Aug 29, 2011, 11:01 PM
VulpesPosted Aug 29, 2011, 6:17 PM