• 守护进程函数——内部的小范围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);
                }
            }

  • 相关阅读:
    jQuery easyui datagrid pagenation 的分页数据格式
    Mysql操作符号
    jquery JSON的解析方式
    线程有几种状态
    工作日志2014-07-07
    leetcode
    Fragment中的setUserVisibleHint()方法调用
    Android开发:Eclipse中SqliteManager插件使用
    海南出差报告总结(案件录入与案件追踪系统)
    Python学习十四:filter()
  • 原文地址:https://www.cnblogs.com/changbaishan/p/10266549.html
Copyright © 2020-2023  润新知