private int idCodeNum = 6; //设置验证码的位数 public void GetCode(string phoneNum) { //获取验证码 timerSend = new Timer(1000); timerSend.AutoReset = true; timerSend.Elapsed += Timer_Elapsed; _interval = SecondNum; timerSend.Start(); //在验证码有效期内,再次请求验证码,需要先关闭上一次的 if (timerTime != null) { timerTime.Close(); timerTime.Dispose(); } //验证码的有效期 timerTime = new Timer(1000); timerTime.AutoReset = true; timerTime.Elapsed += TimerTime_Elapsed; timerTime.Start(); idCodeTime = SaveTime; IdCode = RandomCode.RandomCodeCommand(idCodeNum); PhoneNum = phoneNum; }