0

I have a quick question.

I want to run some come when my application exits, wherever in the winform application it may be. The reason is that the user adds/changes data in the application in different forms, and I have it set to save different data to My.Settings. When the application exits, I want it all to be saved to a text file, to be loaded when the application is next started up. I cannot save to text file whenever the data is changed because it is changing too many times, so for ease of access, I save it My.Settings. I know how to save the data to a text file, I just want to know how can I have it run the code to save data to the text file WHEN the application is exiting.

Centaurian
  • 277
  • 1
  • 3
  • 11
  • VB saves MySettings when the app is shutting down by default. Project Properties -> Application. Are you after something different? – Ňɏssa Pøngjǣrdenlarp Jul 02 '14 at 13:24
  • I am trying to make the application portable. I understand My.Settings is saved on the computer, not to the application. I want it to be portable, so everything is saved to the text file and My.Settings is cleared. I am only using My.Settings to make it easier to change and save data. – Centaurian Jul 02 '14 at 13:38
  • 1
    in that case, there is an Application Shutdown event where you could save the values. see http://msdn.microsoft.com/en-us/library/036kk0as(v=vs.90).aspx – Ňɏssa Pøngjǣrdenlarp Jul 02 '14 at 13:45
  • Thanks, I can't choose it as an answer. – Centaurian Jul 03 '14 at 10:49

1 Answers1

1

VB allows you to add code to perform tasks when your application Starts or Shuts down. To access these, go to Project Properties -> Application Click "View Application Events".

This will open a file very much like a form code window. From the left/Declarations menu select MyApplication Events, then select ShutDown from the event list. This will bring up this:

Private Sub MyApplication_Shutdown(sender As Object, 
             e As EventArgs) Handles Me.Shutdown
  ' your code
  ' to executes when the application is shutting down

End Sub
Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178