内联委托和With语句

时间:2018-01-30 12:05:54

标签: vb.net asynchronous delegates inline with-statement

假设下面的代码:

    BeginInvoke(New Action(Sub()
                         Dim i As Integer = 0
                         Do While i < selectedRows.Count
                           myGridView.SelectRow(myGridView.GetRowHandle(selectedRows(i)))
                           i += 1
                         Loop
                       End Sub))

任何人都能解释一下为什么如果我用这样的With语句写它:

With myGridView
  BeginInvoke(New Action(Sub()
                           Dim i As Integer = 0
                           Do While i < selectedRows.Count
                             .SelectRow(.GetRowHandle(selectedRows(i)))
                             i += 1
                           Loop
                         End Sub))
End With

调试器抛出一个空引用异常,我无法解释

0 个答案:

没有答案