I am developing a smart device application in Visual Studio 2005 for a Symbol handheld pocket pc device. I have two forms for the sake of this discussion lets just label them Form1 and Form2. Form1 is the login form that is loaded by the application using the following code:
Application.Run(new Form1());
After the user is authenticated on Form 1 I create a new instance of Form2 and open it using the following code:
Form2 frm = new Form2();
frm.ShowDialog();
There are now two instances running one of Form1 and one of Form2. I know this because when I check the system memory I can see both processes. My question. If I am on Form2 and I create a exit button how do I close the entire application. How do I close both forms and end both instances. I have tried Application.Exit() but this doesnt work because I cannot close the instance of Form1 from the instance of Form2. I have tried this.Dispose(), but this only closes Form2. I have tried to execute a control on Form1 that contains Application.Exit() from Form2 but this doesnt close both instances it closes both screens but doesnt kill the processes. Is there any way to exit the application entirely from from Form2 or do I have to make the user go back to Form1 to exit the application Any suggestions would be an extreme help. Thanks.

Exiting a Smart Device Application
Emmanuel Huna
Hi Anthony,
Try add a module in your project and declare a public form1, so you can see it anywhere in your application.
Jassim Rahma
pessi
Make sure you're running latest version of NETCF and there are no other threads running in your application. Also try debugging it, perhaps you got into some kind of loop on your attempt to exit, e.g. through events.
BachP
May be this one will help you...
Instead of directly using Application.Run(new Form1());
try, Public static Form1 objForm1 = new Form1(); Application.Run(objForm1); in Program.cs
Then, to close both the forms from form2,
(1) you can call Program.objForm1.close(); or Program.objForm1.Dispose(); to close form1
(2) call this.close(); to close form2
joyson
François-Régis Colin
Hello Anthony,
It is right to call Application.Exit() to exit entire application. This method will close all the forms in your application.
Furthermore, It is recommanded to hide Form1 when Form2 displays, so that only one form will be shown in Running Programs List.
So you can add code: this.hide(); before frm.ShowDialog();
Best Regards,
Zero Dai - MSFT
mbp24
I am developing a smart device application in Visual Studio 2005 for a Symbol handheld pocket pc device. I have two forms for the sake of this discussion lets just label them Form1 and Form2. Form1 is the login form that is loaded by the application using the following code:
Application.Run(new Form1());
After the user is authenticated on Form 1 I create a new instance of Form2 and open it using the following code:
Form2 frm = new Form2();
frm.ShowDialog();
There are now two instances running one of Form1 and one of Form2. I know this because when I check the system memory I can see both processes. My question. If I am on Form2 and I create a exit button how do I close the entire application. How do I close both forms and end both instances. I have tried Application.Exit() but this doesnt work because I cannot close the instance of Form1 from the instance of Form2. I have tried this.Dispose(), but this only closes Form2. I have tried to execute a control on Form1 that contains Application.Exit() from Form2 but this doesnt close both instances it closes both screens but doesnt kill the processes. Is there any way to exit the application entirely from from Form2 or do I have to make the user go back to Form1 to exit the application Any suggestions would be an extreme help. Thanks.
Rozee
The only other thing you would really need to worry about is the menu bar, if you're using one, you'll want to disable it while the logon panel is visible.
Magnus Müller
No, there's only one process and one instance with two forms. "System memory" does not show processes, it shows active windows.
Applictaion.Exit() would close both forms.
Of course if second modal form is shown you can't do anything with Form1 but you can simply call Application.Exit() in second form.