Exiting or Closing a .NETCF application

For the better part of today I was trying to get the Form.Close() event of my applications’ main form to get fired. But no matter what it seemed to not to get fired. And in the process of trying to figure out why it was not so, I found out a thing or two as well.

1. You should not use the Application.Exit() method to close the application. This makes the app to terminate the execution and return control to the system. ow you may say, that it is what you needed to do. But the bad part is this will not trigger the Close() or Closing() methods and hence the clean-up code is not performed. Also, if you have manually put any procs to execute in either of these events then they will not get executed.

So I changed from Application.Exit() this.Close(). But, still my Closing() event was not getting fired. So I delved further and discovered this. In .NETCF apps, the MinimizeBox property of the form is set to True by default. This is done to enhance the app performances. So this way, when the user clicks on the X button on the Top, the form is minimized. And hence, is the form is called again, it is being called from the memory; improving application performance. This is good in mos cases where you want the application to remain in the memory once it is loaded. But in cases where you want the application to quit, when closed, this is not good behavior. So what you have to do is to set the MinimizeBox property to False. Then the X on top righthand corner of the form will change into a OK. And clicking OK will actually quit the application.

Here is my code sample asking the user to confirm exiting application etc.

if (MessageBox.Show(“Do you want to Exit the application?”, “Confirm”, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
{
//Do whatever needs to be done.
this.Close();
}
else
e.Cancel = true; //This prevents the form from being closed.

Well, hope this helps someone out there.


  1. Health net

    What a nice site, been surfing on it for the whole night and day and i neva got bored for a single minute. Keep up your good work and all of the best in everything you do!🙂

  2. keno online

    Lovely to see such a wonderful site. Thank you

  3. george

    thanks! you saved my time!

  4. Nelly

    Good work! Thanks

  5. Jonathan

    Thanks. That information is just what I needed.
    It is typical of Microsoft to change the meaning of ‘X’ for one of their platforms. If they just want to minimise something use the minimise symbol ‘_’. Aargh!

  6. Peter

    Well done! The article really helped me.

  7. Very good article. I’m going through a few of these issues as well..

  8. No matter if some one searches for his vital thing,
    thus he/she wishes to be available that in detail, so that thing is maintained over here.

  9. Hi there to every one, the contents existing
    at this web page are actually remarkable for people experience,
    well, keep up the nice work fellows.

  10. What’s up, this weekend is good in support of me, because this point in time i am reading this fantastic educational post here at my house.

  11. I got this website from my pal who shared with me concerning this web
    site and now this time I am browsing this website and reading very informative articles at this place.

  12. Good article. I will be experiencing a few of these issues
    as well..

  13. This paragraph is in fact a good one it helps new internet visitors, who are wishing in favor of
    blogging.




Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s



%d bloggers like this: