Exemplo n.º 1
0
        static void Main(string[] args)
        {
            SetConsoleWindowVisibility(Visible);
            notifyIcon.DoubleClick += (s, e) =>
            {
                Visible = !Visible;
                SetConsoleWindowVisibility(Visible);
            };
            notifyIcon.Icon    = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
            notifyIcon.Visible = true;
            notifyIcon.Text    = "实名制信息推送程序【鄂州市劳保】";

            // 初始化上传标段参数
            if (!HjApiCaller.TryInit())
            {
                Environment.Exit(0);
            }

            try
            {
                Task.Factory
                .StartNew(StartUpload)
                .ContinueWith(t =>
                {
                    anyExceptions = (t.Exception != null);
                    Application.Exit();
                });
            }
            catch (Exception e)
            {
                LogUtils4Error.Logger.Error(e.Message);
            }
            finally
            {
                Application.Run();
                notifyIcon.Visible = false;

                // 1、日志记录完成
                LogUtils4Debug.Logger.Debug($"================={ HjApiCaller.ProjectName },已上传完成!=================");
                LogUtils.Logger.Info($"{ HjApiCaller.ProjectName },{ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") },上传完成并{ (anyExceptions ? "有" : "无")}异常发生");

                DBHelperMySQL.Dispose();
                // 2、打开新的程序
                var p = Process.Start(Assembly.GetExecutingAssembly().Location);

                Environment.Exit(0);
            }
        }