My.Setting value is wrong aftar Application.Restart

回答済み My.Setting value is wrong aftar Application.Restart

  • 2012年4月14日 9:51
     
     
    Dear All,

    I'm using my.settings to save the load time of the solution. When my.settings.load_time value is changed and use my.settings.load_time.save() to save them. When I quit the application and manually start it again, the newly saved settings are used.

    When I use either application.restart. The application will use the old values for my.settings.

    My question is..
    Is there a way to restart the application using either application.restart which will use the newly saved my.settings values?

すべての返信

  • 2012年4月14日 10:29
     
     回答の候補
    Could it be that you do not save the settings before doing restart? I.e. need to call the save before the restart.

    Regards David R
    ---------------------------------------------------------------
    The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones.
    Object-oriented programming offers a sustainable way to write spaghetti code. - Paul Graham.
    Every program eventually becomes rococo, and then rubble. - Alan Perlis
    The only valid measurement of code quality: WTFs/minute.

  • 2012年4月14日 16:11
     
     

    Do you save your settings before restarting?

    My.settings.save

    then

    Application.restart



    Muscalu Ștefan ~~~~ Student

  • 2012年4月14日 16:21
     
     

    Hmm. I was just musing since I can't see your code and it seems a likely possibility.

    May be that on restart the settings are not re-read. Wonder what the help says? [It's not actually specified, but does say the environment is unchanged. That seems to imply it does nor re-read settings.] Perhaps you have to reload the settings after a restart if they have changed.


    Regards David R
    ---------------------------------------------------------------
    The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones.
    Object-oriented programming offers a sustainable way to write spaghetti code. - Paul Graham.
    Every program eventually becomes rococo, and then rubble. - Alan Perlis
    The only valid measurement of code quality: WTFs/minute.

  • 2012年4月16日 2:08
     
      コードあり

    Thanks for all your replay..

    I already use my.settings.save and my.settings.reload method, but it can't solve my problem yet..

    this is my code :

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            My.Settings.Reload()
            TextBox1.Text = My.Settings.Teste
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            My.Settings.Teste = TextBox1.Text
            My.Settings.Save()
            MsgBox("Saved!")
        End Sub
    
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Application.Restart()
        End Sub


  • 2012年4月16日 9:16
     
     回答済み

    When you develop your application you have two sets of settings:

    1)Debugger settings (applied to your application when you run it inside visual studio/visual basic express) 

    2)Application settings(applied to your application when you run it outside visual studio/visual basic express)

    When you run your application from your IDE(visual studio/visual basic express) and you restart it, that restarted instance of your application will not have the debugger attached and will have another set of settings.

    When i used your code, i experienced what I've just explained, but not loss of settings each time the application is restarted...



    Muscalu Ștefan ~~~~ Student


  • 2012年4月17日 1:41
     
     

    hi, muscalu stefan gabriel

    jeez, i never think about it.

    yes, it work for me when i run it outside Visual Studio.

    thanks for your help, it already solved my problem :)