|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Confused about Application.ExitWhy will the following code snippet run forever?
While(true) { if(MessageBox.Show("Exit now?","Close?") == DialogResult.OK) { Application.Exit(); } } How do you exit an application from within a While loop? "William Sullivan" <WilliamSulli***@discussions.microsoft.com> wrote in You don't - you have to return to the message pump so that it can return message news:7EDDC9E2-BA82-4B48-91FE-3A089179CB9B@microsoft.com... > Why will the following code snippet run forever? > > While(true) > { > if(MessageBox.Show("Exit now?","Close?") == DialogResult.OK) > { > Application.Exit(); > } > } > > How do you exit an application from within a While loop? from the Run() method. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsapplicationclassexittopic.asp I don't think that there is an equivalent of the C function exit(). Foolish me. Just after I posted, I realized I was trying to use
Application.Exit in the constructor of an object I was creating before calling Application.Run(). Instead, I just threw an exception and caught it in Main() so I could then return prior to running the pump. Thanks. Show quote "Nick Hounsome" wrote: > > "William Sullivan" <WilliamSulli***@discussions.microsoft.com> wrote in > message news:7EDDC9E2-BA82-4B48-91FE-3A089179CB9B@microsoft.com... > > Why will the following code snippet run forever? > > > > While(true) > > { > > if(MessageBox.Show("Exit now?","Close?") == DialogResult.OK) > > { > > Application.Exit(); > > } > > } > > > > How do you exit an application from within a While loop? > > You don't - you have to return to the message pump so that it can return > from the Run() method. > > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsapplicationclassexittopic.asp > > I don't think that there is an equivalent of the C function exit(). > > > Hello Nick,
You can substitute the C function exit() with System.Environment.Exit(): http://msdn.microsoft.com/library/?url=/library/en-us/cpref/html/frlrfSystemEnvironmentClassExitTopic.asp?frame=true Regards. Show quote "Nick Hounsome" <nh***@nickhounsome.me.uk> escribió en el mensaje news:LEZMf.62912$Q22.21967@fe1.news.blueyonder.co.uk... | | "William Sullivan" <WilliamSulli***@discussions.microsoft.com> wrote in | message news:7EDDC9E2-BA82-4B48-91FE-3A089179CB9B@microsoft.com... | > Why will the following code snippet run forever? | > | > While(true) | > { | > if(MessageBox.Show("Exit now?","Close?") == DialogResult.OK) | > { | > Application.Exit(); | > } | > } | > | > How do you exit an application from within a While loop? | | You don't - you have to return to the message pump so that it can return | from the Run() method. | | http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsapplicationclassexittopic.asp | | I don't think that there is an equivalent of the C function exit(). | | |
|||||||||||||||||||||||