I do not understand if you want:
- You want to upload your form somewhere else besides Main ()
- Or launch a console or service application using no interface.
For (1) :
static void main() { //Your program starts running here<<< //Do some stuff... FormRunner a = new FormRunner(); a.RunForm(); } // << And ends here class FormRunner { public void RunForm() { Application.Run(new Form()); } //You could call which ever form you want from here? } // << And ends here
What you need to know, your program starts on the first line of the main line and ends on the last. However , when you call Application.Run(FORM) , it loads the Windows message loop for this form. Its special loop, which maintains the program is still mostly and waiting for events (they are called Windows messages in the win32 API)
And so the program does not end until the user clicks the close button. When this happens, it means that your program will actually return from its Main.
(2) So now, if you just want to use a clean console application without forms:
static void main() { AcceptInputs() DrawScreen() //Do something else. //Make sure your flow stays within the main } // << Once you come here you're done. void AcceptInputs() { while(true) { //Keep accepting input break; // Call break when you're done. You'll be back in the main } }
I hope this helps.
gideon
source share