Example #1
0
        /// <summary>
        /// 管理线程(发送心跳)
        /// </summary>
        static void ManageThread()
        {
            LogUtil.MsgLog("heart start ...!", "manageLog");
            while (true)
            {
                // 根据网络状况同步信息
                if (!NetStateUtil.LocalConnectionStatus())
                {
                    LogUtil.MsgLog("Network connectionless! Try again in 5 minutes", "manageLog");
                    Thread.Sleep(5 * 60000);
                    continue;
                }

                try
                {
                    /// 每十分钟发送一次心跳
                    UploadWebservice.UploadWebservice webservice = new UploadWebservice.UploadWebservice();
                    webservice.Timeout = 10000;
                    string projectInfo = XmlUtil.CreateHeart();
                    string result      = webservice.InMyHeart(projectInfo);
                    LogUtil.MsgLog("I'm Life...- " + result, "manageLog");
                    /// 在这里做线程维护,先空着
                }
                catch
                {
                    Thread.Sleep(60000);
                    LogUtil.MsgLog("WebService not runing! Try again in 5 minutes", "manageLog");
                }

                Thread.Sleep(10 * 60000);
            }
        }
Example #2
0
        /// <summary>
        /// 读取人员信息并发送
        /// </summary>
        static void ReadHumanData()
        {
            LogUtil.MsgLog("human up start!", "humanLog");
            while (true)
            {
                // 根据网络状况同步信息
                if (!NetStateUtil.LocalConnectionStatus())
                {
                    LogUtil.MsgLog("Network connectionless! Try again in 5 minutes", "humanLog");
                    Thread.Sleep(5 * 60000);
                    continue;
                }

                // 从数据库读取数据并转换未Xml字符串
                ReadDatabase read = new ReadDatabase();
                List <Human> data = read.ReadHumanInfo();
                if (data == null || data.Count() == 0)
                {
                    LogUtil.MsgLog("There is no new data!", "humanLog");
                    Thread.Sleep(15 * 60000);
                    continue;
                }

                // 调用webservice上传人员读卡信息
                try
                {
                    string ListHuman = XmlUtil.CreateHumanXml(data);
                    UploadWebservice.UploadWebservice webservice = new UploadWebservice.UploadWebservice();
                    webservice.Timeout = 15000;
                    // 执行WebService并返回结果
                    string result = webservice.UpHumanInfo(ListHuman);
                    HumanResultHandle(result);
                }
                catch
                {
                    Thread.Sleep(5 * 60000);
                    LogUtil.MsgLog("WebService not runing! Try again in 5 minutes", "humanLog");
                }
                Thread.Sleep(60000);
            }
        }