How can I check if a program is running for the first time?

后端 未结 3 1338
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-11 02:53

My program sets its display based on if the program is running for the first time or not. In order to determine if the program is running for the first time I am currently u

3条回答
  •  鱼传尺愫
    2020-12-11 03:29

    Seems that your problem is actually that if you move executable to another location/folder on the same pc, it loses somehow the information about the fact that it was already run at least once.

    Using UserSettings, on Properties.Settings.Default.FirstRun should resolve your problem.

    Something like this, a pseudocode:

    if(Properties.Settings.Default.FirstRun == true)
    { lblGreetings.Text = "Welcome New User";
      //Change the value since the program has run once now
      Properties.Settings.Default.FirstRun = false;
      Properties.Settings.Default.Save(); }
    else
    { lblGreetings.Text = "Welcome Back User"; }
    

    Look on this sample how to achieve that in more detailed way.

提交回复
热议问题