• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C#启动进程和杀死进程

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
     /// <summary>
        /// 杀死进程
        /// </summary>
        private void KillProcesses()
        {
            var cfn = GetAppsettingStr("checkin-filefolder-name");
            var ofn = GetAppsettingStr("outmoney-filefolder-name");
            var ifn = GetAppsettingStr("inmoney-filefolder-name");
            foreach (var p in Process.GetProcesses())
            {
                if (p.ProcessName == cfn || p.ProcessName == ofn || p.ProcessName == ifn)
                {
                    p.Kill();
                }
            }
        }

        /// <summary>
        /// 启动进程
        /// </summary>
        private void StartProcesses()
        {
            var list = new List<string>();
            var cfn = GetAppsettingStr("checkin-filefolder") + GetAppsettingStr("checkin-filefolder-name");
            var ofn = GetAppsettingStr("outmoney-filefolder") + GetAppsettingStr("outmoney-filefolder-name");
            var ifn = GetAppsettingStr("inmoney-filefolder") + GetAppsettingStr("inmoney-filefolder-name");
            list.Add(ofn);
            list.Add(ifn);
            list.Add(cfn);
            
            foreach (var li in list)
            {
                Process.Start(li + ".exe");
            }
        }

再加上从app.config 文件里获取数据

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="StartUpgrade.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </sectionGroup>
    </configSections>
  <appSettings>
    <!-- checkin 文件夹和文件名 -->
    <add key="checkin-filefolder" value="D:\NotePad++\"/>
    <add key="checkin-filefolder-name" value="npp.6.1.3.Installer"/>
    
    <!-- 出钞 文件夹和文件名 -->
    <add key="outmoney-filefolder" value="D:\NotePad++\"/>
    <add key="outmoney-filefolder-name" value="npp.6.1.3.Installer"/>
    
    <!-- 入钞 文件夹和文件名 -->
    <add key="inmoney-filefolder" value="D:\NotePad++\"/>
    <add key="inmoney-filefolder-name" value="npp.6.1.3.Installer"/>
    
    <!-- 字节数组 -->
    <add key="bytearrary" value="10240"/>
    <add key="upload-path" value="E:\Projects\Hotels\StartUpgrade\StartUpgrade\File\"/>
    <add key="upload-url" value="http://192.168.1.200:8077/UpgradeFiles/"/>
    
    <!-- 机器id -->
    <add key="machineid" value="888"/>
  </appSettings>
    <system.serviceModel>
      <bindings />
      <client />
    </system.serviceModel>
    <applicationSettings>
      <StartUpgrade.Properties.Settings>
            <setting name="StartUpgrade_IStartUpgrade_UpgradeFile" serializeAs="String">
                <value>http://192.168.1.155:8013/DataService/WebService/Interface/UpgradeFile.asmx</value>
            </setting>
        </StartUpgrade.Properties.Settings>
    </applicationSettings>
 
</configuration>

是这样获取app.config数据的:

        /// <summary>
        /// 获取配置文件里appsettings的数据
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public string GetAppsettingStr(string str)
        {
            var appReader = new AppSettingsReader();
            return appReader.GetValue(str, typeof(string)).ToString();
        }    

 

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Oracle19c新特性Automaticindexing自动化索引发布时间:2022-07-13
下一篇:
Qt开启C++线程里并访问界面发布时间:2022-07-13
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap