Example #1
0
 /// <summary>
 /// 断线重连
 /// </summary>
 /// <param name="client"></param>
 private void ReconnectOpcAsync()
 {
     while (true)
     {
         if (!this.OpcStatus && this.Address.ReconnectEnable)
         {
             ReconnectStartingHandle?.Invoke(this);
             ServerStateDesc = "连接已断开,尝试重连";
             ServerStartTime = DateTime.Now.ToString() + "   ";
             //成功连接后直接返回
             if (Connect().Result)
             {
                 ServerStateDesc = "重连成功";
                 ServerStartTime = DateTime.Now.ToString() + "   ";
                 ReconnectCompleteHandle?.Invoke(this);
                 return;
             }
             //连接失败则循环继续
             else
             {
                 //重连时间间隔
                 Thread.Sleep(this.Address.ReconnectInterval * 1000);
             }
         }
         else
         {
             return;
         }
     }
 }
Example #2
0
 /// <summary>
 /// OPC服务器重新连接中事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void M_UaOpc_ReconnectStarting(object sender, EventArgs e)
 {
     ServerStateDesc = "连接已断开,尝试重连";
     ReconnectStartingHandle?.Invoke(this);
 }