zoukankan      html  css  js  c++  java
  • 守护进程函数——内部的小范围try catch 增强了 while死循环执行的 可靠性

    void Watch()
            {
                try
                {
                    LogHelper.WriteLog("WatchService Watch Start!");
                    while (true)
                    {
                        try
                        {
                            if (ReadConfig() != "true")
                            {
                                HideTaskBarAndStartButton(0);
                            }
                            else
                            {
                                HideTaskBarAndStartButton(1);
                            }
                        }
                        catch (Exception)
                        {

                                  //这个try catch 用得非常好 ,不能因小(显示/隐藏任务栏)失大(while死循环崩溃)
                        }

                        Process[] process = Process.GetProcessesByName("Zxt.TaxSelfHelp.Client");
                        //LogHelper.WriteLog("WatchService Watch Client process.Length:" + process.Length);
                        if (process.Length == 0)
                        {
                            process = Process.GetProcessesByName("Zxt.TaxSelfHelp.Update");
                            //LogHelper.WriteLog("WatchService Watch Update process.Length:" + process.Length);
                            if (process.Length == 0)
                            {
                                LogHelper.WriteLog("Process.Start " + Application.StartupPath + "\Zxt.TaxSelfHelp.Client.exe");
                                //ProcessStartInfo processStartInfo = new ProcessStartInfo();
                                //processStartInfo.Verb = "runas";
                                //processStartInfo.FileName = Application.StartupPath + "\Zxt.TaxSelfHelp.Client.exe";
                                //Process.Start(processStartInfo);

                                Process proc = new Process();
                                proc.StartInfo.FileName = "Zxt.TaxSelfHelp.Client.exe";
                                proc.StartInfo.WorkingDirectory = Application.StartupPath;
                                proc.Start();
                            }
                        }
                        Thread.Sleep(Second * 1000);
                    }

                }
                catch (Exception ex)
                {
                    LogHelper.ErrorLog("WatchService", ex);
                }
            }

  • 相关阅读:
    cocos2dx 2.14使用UUID
    cocos2dx游戏项目总结(持续更新)
    window mac iPhone 三种比较相似的字体
    【luogu P4762】字符串合成 / Virus synthesis(PAM)(DP)
    【luogu P7796】图书管理员 / POLICE(并查集)(树状数组)
    【luogu P5494】【模板】线段树分裂(线段树合并)(线段树分裂)
    【luogu P2595】多米诺骨牌(插头DP)(容斥)
    送分大水题(高维前缀和)(高维差分)
    【luogu P6880】Bus / 奥运公交 / オリンピックバス(最短路)
    【luogu P1879】Corn Fields G / 玉米田++ / 玉米田(加加强版)(状压DP)(轮廓线DP)
  • 原文地址:https://www.cnblogs.com/changbaishan/p/10266549.html
Copyright © 2011-2022 走看看