【问题标题】:Sharing app.config共享 app.config
【发布时间】:2014-05-16 16:30:08
【问题描述】:

我有 2 个应用程序:

  • Windows 服务(带有用于配置网站和 api 的 HTTP 侦听器)
  • 控制实用程序(WPF 应用)

控制实用程序的要求非常简单:

  • 启动/停止服务
  • 启动指向网站的浏览器(例如http://local:5555

查找名为“MyService”的 Windows 服务、检索其状态并在需要时启动它非常简单。但是,如何使用正确的链接启动浏览器? HTTP 侦听器正在侦听的端口可在我的 Windows 服务应用程序的 app.config 中进行配置,并且无法发现侦听器。 app.config 可以在 2 个应用程序之间共享吗?

我知道ConfigurationManagerOpenExeConfiguration(),但这会导致其他问题:

  • 我要知道Windows服务的安装路径
  • 读取配置可能会导致读锁
  • 如果配置文件是加密的,我必须知道密钥

还有其他解决方案可以实现这一点吗?

【问题讨论】:

    标签: c# .net windows-services app-config


    【解决方案1】:

    您可以使用注册表来交换数据。

    // Create a Subkey
    RegistryKey newKey = Registry.CurrentUser.CreateSubKey("SOFTWARE\\SuperSoft\\App");
    
    // Write Values to the Subkey
    newKey.SetValue("Value1", "Content1");
    newKey.SetValue("Value2", "Content2");
    
    // read Values from the Subkey
    if (SubKeyExist("SOFTWARE\\SuperSoft\\App"))
    {
      RegistryKey myKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\SuperSoft\\App");
      string firstApp = (string)myKey.GetValue("Value1");
      string secondApp = (string)myKey.GetValue("Value2");
    }
    

    【讨论】:

    • 奇怪,注册表在我内心激起的情绪与当我回想起我童年第一次接触热盘时的那一刻时一样。哦,好吧..让我们那样做吧..我想......
    猜你喜欢
    • 1970-01-01
    • 2010-09-30
    • 1970-01-01
    • 2017-08-27
    • 1970-01-01
    • 2014-06-14
    • 1970-01-01
    • 2010-12-12
    • 2011-02-14
    相关资源
    最近更新 更多