/// <summary> /// 计时器事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TimerEvent(object sender, ElapsedEventArgs e) { TmphRASCONNSTATUS structure = new TmphRASCONNSTATUS(); int lpcb = 0; int lpcConnections = 0; structure.dwSize = Marshal.SizeOf(structure); int nErrorValue = RasEnumConnections(this.Rasconn, ref lpcb, ref lpcConnections); switch (nErrorValue) { case 0: break; case 0x25b: this.Rasconn = new TmphRASCONN[lpcConnections]; lpcb = this.Rasconn[0].dwSize = Marshal.SizeOf(this.Rasconn[0]); nErrorValue = RasEnumConnections(this.Rasconn, ref lpcb, ref lpcConnections); break; default: this.ConnectNotify(this.GetErrorString(nErrorValue), 3); return; } if (nErrorValue != 0) { this.ConnectNotify(this.GetErrorString(nErrorValue), 3); } else if ((lpcConnections < 1) && this.bConnected) { this.bConnected = false; this.ConnectNotify("连接中断.", 0); } else { for (int i = 0; i < lpcConnections; i++) { nErrorValue = RasGetConnectStatus(this.Rasconn[i].hrasconn, ref structure); if (nErrorValue != 0) { this.ConnectNotify(this.GetErrorString(nErrorValue), 3); return; } if ((structure.rasconnstate == TmphRASCONNSTATE.RASCS_Connected) && !this.bConnected) { this.bConnected = true; this.ConnectNotify("成功连接到" + this.Rasconn[i].szEntryName + '.', 2); } if ((structure.rasconnstate == TmphRASCONNSTATE.RASCS_Disconnected) && this.bConnected) { this.bConnected = false; this.ConnectNotify("连接中断.", 0); } } } }
private static extern int RasGetConnectStatus(int hrasconn, ref TmphRASCONNSTATUS lprasconnstatus);