再次,这是我的情况。 基本上,我想要清除行并每隔一定时间添加行。我最简单的代码如下:
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim wreturnCode1 As Integer = System.Threading.ThreadPool.QueueUserWorkItem(New System.Threading.WaitCallback(AddressOf RepeatAction), cancellation.Token)
End Sub
Private Sub RepeatAction(ByVal obj As Object)
Dim token As System.Threading.CancellationToken = CType(obj, System.Threading.CancellationToken)
FormTimer.Enabled = True
AddHandler FormTimer.Elapsed, AddressOf AutoTaskRepo
End Sub
Private Async Sub AutoTaskRepo()
FormTimer.Enabled = False
DataGridView1.Rows.Clear()
DataGridView1.Rows.Add()
DataGridView1.Rows.Add()
DataGridView1.Rows.Add()
DataGridView1.Rows.Add()
DataGridView1.Rows.Add()
DataGridView1.Rows.Add()
FormTimer.Enabled = True
End Sub
在datagridview中我有5列。当我添加行时,等待n秒并清除行并再次添加行。
Here is the table in the first iteration
下一次迭代工作正常,但在清除行后的某个时刻,系统会抛出NullReferenceException
。
请注意,我不需要数据源和数据表。我想手动添加并手动清除datagridview中的数据。 SomeHelp