public MainWindow() { InitializeComponent(); string serverIP = ConfigurationManager.AppSettings["MarketIp"]; string serverPort = ConfigurationManager.AppSettings["MarketPort"]; marketType = ConfigurationManager.AppSettings["MarketType"]; user = ConfigurationManager.AppSettings["user"]; pwd = ConfigurationManager.AppSettings["pwd"]; startRequestTime = ConfigurationManager.AppSettings["Req_product_time"]; marketBlockingCollection = new BlockingCollection <string>(); marketTcpIpBlockingCollection = new BlockingCollection <MarketTcpIp>(); lstExchange = new List <Exchange>(); string value = ConfigurationManager.AppSettings["exceptExchange"]; lstUnExchange = new List <string>(); if (!string.IsNullOrEmpty(value)) { lstUnExchange = new List <string>(value.Split(',')); } this.Text = this.Text + "_" + marketType; marketErrorLoger = new WriteLog("./log/marketError.log", LogLevel.ALL); marketTcpClient = new MarketTcpIp(serverIP, int.Parse(serverPort)); marketTcpClient.mainWindow = this; marketTcpClient.setVersion(100); marketTcpClient.Connect(); marketTcpClient.setSize(1024 * 1024 * 4); isSave = true; }
/// <summary> /// 执行重连线程 /// </summary> public void ExecuteReconnectThread() { while (isSave) { try { MarketTcpIp marketTcpIp = marketTcpIpBlockingCollection.Take(); // if (!marketTcpIp.client.isConnected){ if (!marketTcpIp.isOnReconnecting) { Thread.Sleep(1000); PrintToTxt("正在重连..."); marketTcpIp.ReConnect(); } } catch (Exception ex) { marketErrorLoger.log(LogLevel.SYSTEMERROR, ex.ToString()); } } }