我在这里有我的代码来发送短信:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
count = DataTable1DataGridView.Rows.Count
For i As Integer = count To 1 Step -1
Try
If SerialPort1.IsOpen Then
'dataGridView1()
' TextBox1.Text = Me.dataGridView1.Rows(0).Cells(2).Value.ToString()
With SerialPort1
.Write("AT" & vbCrLf)
.Write("AT+CMGF=1" & vbCrLf)
.Write("AT+CMGS=" & Chr(34) & DataTable1DataGridView.Rows(i - 1).Cells(2).Value.ToString & Chr(34) & vbCrLf)
.Write(ES_MSG.Rows(0).Cells(0).Value.ToString & Chr(26))
End With
Else
MsgBox("Error on the port selected")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
If (i = count) Then
Exit For
Timer1.Enabled = False
Timer1.Stop()
End If
MsgBox("Message Sent!")
Next
Timer1.Enabled = False
Timer1.Stop()
End Sub
我通过 button_click 启用了计时器。我的问题是无论我将 Timer.Stop() 和 Timer.Enabled = False 放在哪里,计时器似乎都不会停止。更糟糕的是,当出现错误或发送消息时,即使我的数据网格中的计数很小,弹出窗口似乎也会无限出现。任何人都可以分享想法吗?我真的需要它。谢谢。