/// <summary> /// 定时查询服务器监听timer /// </summary> /// <param name="sender">timer对象</param> /// <param name="e">事件参数信息</param> private void connectTimer_Elapsed(Object sender, ElapsedEventArgs e) { // 每2秒从服务器获取更新数据并推送至界面显示 try { Stream resultStream = GetResponseMessage(); List <UserInfo> userInfoList = AnalysisService.AnalysisJsonStream(resultStream, mEncoding); // 判断解析后数据是否为空 if (userInfoList != null && userInfoList.Count > 0) { Publish(userInfoList); Console.WriteLine("更新数据时间:" + DateTime.Now); } else { Console.WriteLine("解析数据为空"); } } catch (Exception ex) { Console.WriteLine("异常信息:" + ex); } finally { // 重新开启查询timer connectTimer.Start(); } }