How can I set up a class such that its the main one and so that it is the first to be run by the program?
Printable View
How can I set up a class such that its the main one and so that it is the first to be run by the program?
Create a method called 'Main' and change the startup object option in the project settings.
If by class you mean a form, then you don't need to create a method called Main, you just need to change the startup object to that form.
Thanks. Ill try that.
Hi. Im creating a WPF project and would like to make the Main method or my Main class to run o startup. But I dont get the option in project properties.
Then you should have posted in the WPF forum instead. I never used WPF so I can't answer your question.
Sorry. I didnt realise itd make a difference.
Just as in WinForms, if you want to create your own Main method as the application entry point then you have to disable the Application Framework in the project properties. If you do that then the Startup URI becomes Startup Object and automatically switches from a Window to Sub Main.
That said, in most cases you shouldn't be doing this. This is another case of where you should be explaining what you're actually trying to achieve and not how you're trying to achieve it. Why exactly do you want to do what you're suggesting? Quite possibly you should simply be handling the Startup event of the application.