Denaes Posted September 18, 2003 Posted September 18, 2003 I think I'm missing something. I normally end a program with the word "End", which normally works fine. I'm making a program that I need to run a few procedures on FormLoad (actually they're in form activation, cuz they don't work in form load), then after all that, end the program by itself. I tried putting End into the FormLoad event, but that didn't work right, I tried putting it right after all the other subs that needed to be done during activation and the program went a little nutty. Would making a timer and having it 'end' the program after a few ticks work? Is "End" even the proper way to be doing this? the way I'm getting buck nutty results, I"m not so sure Thanks for any advice Quote
*Experts* mutant Posted September 18, 2003 *Experts* Posted September 18, 2003 You shouldnt use End, ever, its not recommended as it doesnt clean up anything, it only shuts down the program. If you form doesnt even get shown then what about not having the form at all and using Sub Main to execute the code and then it will exit automatically when the code in Main is done. Quote
JumpsInLava Posted September 18, 2003 Posted September 18, 2003 Sometimes its nice to use a form app so you can display status if something goes wrong, or you need input if something happens. Both of these work I think. I'm not sure which one is preferred: me.close me.dispose Quote
Denaes Posted September 18, 2003 Author Posted September 18, 2003 I have to look into that. A formless program is definately what I want. I'm just not sure how to set that up. Its not a type of project, right? I found Application.Exit() to exit, but ran into a problem. It just cuts off the program wherever I put it. It would get one character out of my first SendKeys string, then terminate. I added Application.DoEvents after all of the SendKeys, then after each individually and it let 4 characters get through before shutting down. I think a formless program would be better. I'm thinking that I add a module, make it a Shared Sub Main, might need to import the form class for some methods, and theres an option somewhere to choose what the startup Form is, and you can probobly select Sub Main, then just delete the form? I'll look into this later and try it out. Quote
aewarnick Posted September 18, 2003 Posted September 18, 2003 Close is preferred because it calles Dispose and cleans things up. Quote C#
*Experts* mutant Posted September 18, 2003 *Experts* Posted September 18, 2003 You dont need any special type of a project to make app without a form. Simply delete the form, go to your Solution Explorer, right click your project and go to properties and you should see an option called Startup Object. Set it to Sub Main. You dont need to call Application.Exit() if you dont run any form because when the code in Sub Main finishes it automatically exits. Quote
Denaes Posted September 26, 2003 Author Posted September 26, 2003 Sorry to rehash this and bring it back up again, but if me.close and me.dispose are the preferred and professional way to exit an application and cleanup, what about a formless application. I don't have a me. I tried application.close. I tried: dim x as form = new form x.close but the program freaked and threw an exception. Right now I'm still using application.exit() to close on error. Quote
*Experts* mutant Posted September 26, 2003 *Experts* Posted September 26, 2003 If you dont have any forms its logical that you wont use the Close method of the form that the message loop is relaying on :), You can use Application.Exit() Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.