• 通过配置文件判断程序首次启动


    //step 1 .设置配置文件

    App.config:

    <?xml version="1.0"?>
    <configuration>
      <appSettings>
        <add key="IsFirstRun" value="true"></add>
      </appSettings>
    </configuration>

     //step 2.

    注意引用:System.Configuration.dll

    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Linq;
    using System.Text;

    namespace RuiSoft.Common
    {
      public class IsSoftFirstRun
      {

        //返回true为首次启动,返回false为非首次启动
        public static bool IsFirstStart()
        {
          string strIsFirstRun = "false";
          bool isFirstRun = false;
          //strIsFirstRun = ConfigurationManager.AppSettings("IsFirstRun");
          strIsFirstRun = System.Configuration.ConfigurationManager.AppSettings["IsFirstRun"];

          if (string.IsNullOrEmpty(strIsFirstRun) || strIsFirstRun.ToLower() != "true")
          {
            isFirstRun = false;
          }
          else
          {
            isFirstRun = true;
          }
          strIsFirstRun = "false";

          Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
          config.AppSettings.Settings.Remove("IsFirstRun");
          config.AppSettings.Settings.Add("IsFirstRun", strIsFirstRun);
          config.Save();

          return isFirstRun;
        }  
      }
    }

    //step 4. 

    public partial class MainWindow : Window
    {
      public MainWindow()
      {
        InitializeComponent();
        LoadInformation();
      }

      public void LoadInformation()
      {
        if (IsFirstStart())
        {
          txtTest.Text = "首次启动";
        }
        else
        {
          txtTest.Text = "非首次启动";
        }
      }

     }

    //step 4.运行项目下的bin目录下的.exe文件,实现判断首次运行

  • 相关阅读:
    如何拷贝CMD命令行文本到粘贴板
    Linux 系统时钟(date) 硬件时钟(hwclock)
    Android AIDL自动生成Java文件测试
    Windows Tftpd32 DHCP服务器 使用
    Cmockery macro demo hacking
    Linux setjmp longjmp
    GrepCode
    Windows bat with adb
    点分十进制IP校验、转换,掩码校验
    子网掩码、掩码长度关系
  • 原文地址:https://www.cnblogs.com/gnsds/p/3644664.html
Copyright © 2020-2023  润新知