惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
T
Tenable Blog
Project Zero
Project Zero
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
S
Schneier on Security
Scott Helme
Scott Helme
S
Securelist
Know Your Adversary
Know Your Adversary
Vercel News
Vercel News
IT之家
IT之家
V
V2EX
F
Fortinet All Blogs
Simon Willison's Weblog
Simon Willison's Weblog
K
Kaspersky official blog
博客园_首页
T
Tailwind CSS Blog
The GitHub Blog
The GitHub Blog
Spread Privacy
Spread Privacy
Microsoft Security Blog
Microsoft Security Blog
Cisco Talos Blog
Cisco Talos Blog
The Register - Security
The Register - Security
有赞技术团队
有赞技术团队
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
The Hacker News
The Hacker News
L
LINUX DO - 热门话题
Hugging Face - Blog
Hugging Face - Blog
博客园 - 三生石上(FineUI控件)
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
CXSECURITY Database RSS Feed - CXSecurity.com
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Threat Research - Cisco Blogs
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy & Cybersecurity Law Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CERT Recently Published Vulnerability Notes
S
SegmentFault 最新的问题
AWS News Blog
AWS News Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
P
Proofpoint News Feed
The Cloudflare Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Vulnerabilities – Threatpost

博客园 - DotNet1010

.NET 6 的 docker 镜像可以有多小 Code UTF-8 Console GB2312 Linux 中文乱码 穿透式监管与CTP swagger 兼容 docker 转发 配置 rust 条件编译 Debug Release rust-must-know-crates-5ad8 100DayOfRust python C# DES 加密转换 The Little Book of Rust Books C# 高精度定时器 NET number values such as positive and negative infinity cannot be written as valid JSON C# 各种序列化方案比较 Python3 HDF5 中英文混合存储 MVVM WPF 简化 类的开发 websocket-per-message-compression Asp.net Core WebSocket 支持压缩 Redis 监控工具 期货行情查看客户端下载 完美解决windows10磁盘占用100%并出现卡顿、假死无反应 How to disable the unused macros warning? --rust 看阿里架构师是如何在高并发的情景下运筹帷幄
.NET 5 WPF 配置文件变动 程序自动刷新 (reloadOnChange)
DotNet1010 · 2021-01-13 · via 博客园 - DotNet1010
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Primitives;
using System;
using System.Configuration;
using System.Threading;

namespace WpfLiBroker
{
    public class AppConfig
    {

        public static  Microsoft.Extensions.Configuration.IConfiguration config { get; private set; }
        private static DateTime last_changed_time = DateTime.MinValue;
        static AppConfig()
        {
              config = new ConfigurationBuilder()
             .SetBasePath(System.Environment.CurrentDirectory)
             .AddJsonFile("config.json", false, true)
             .Build();

            LoadData(); //测试此处可以不加  这里加上以防万一

            ChangeToken.OnChange(() => {
                var span = DateTime.Now - last_changed_time;
                last_changed_time = DateTime.Now;
                if (span < TimeSpan.FromSeconds(1)){

                    System.Diagnostics.Debug.WriteLine($"{DateTime.Now.ToLongTimeString()} config change do nothing!");
                    return config.GetReloadToken();
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine($"{DateTime.Now.ToLongTimeString()} config change do something!");
                    //**********************************
                     LoadData();
                    //#######################################
                    var data = config.GetReloadToken();
                    return data;
                }
            }
            , ()=> { });// () => autoReset.Set()
        }

        private static void LoadData()
        {
            Account = config.GetSection("account").Get<Account>();
        }


        public static Account Account { get; private set; }
     
    }

    public class Account
    {
        public string login_code { get; set; }

        public string login_pwd  { get; set; }
    }
}

 配置文件:config.json

{
  "account": {
    "login_code": "code",
    "login_pwd": "pwd"
  }
}

主要实现了配置文件修改后 程序绑定的变量自动刷新