Application.Restart()上的枚举错误

时间:2017-05-30 14:27:50

标签: vb.net restart

上次我在这个应用程序上工作时,这突然有了#34; Application.Restart"不再工作了。我不知道它有什么问题,但错误是

System.InvalidOperationException: 'Collection was modified; enumeration operation may not execute

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    If ckNotify.Checked Then
        CreateKey("HKCU\Software\Tool Inc\Inventory\Notify", "True")
        frmMain.Timer1.Enabled = True
    Else
        CreateKey("HKCU\Software\Tool Inc\Inventory\Notify", "False")
        frmMain.Timer1.Enabled = False
    End If

    frmMain.Label5.Text = "Stockroom view: " & Stockkey & ""

    Dim nodes As TreeNodeCollection = frmMain.TreeView1.Nodes
    Dim nodes2 As TreeNodeCollection = frmMain.TreeView2.Nodes
    If nodes.Count > 0 Then
        frmMain.TreeView2.SelectedNode = nodes2(0)
        frmMain.TreeView1.SelectedNode = nodes(0)
    End If

    If ReadKey("HKCU\Software\Tool Inc\Inventory\Stockroom") = ComboBox1.Text Then
        Close()
    Else
        CreateKey("HKCU\Software\Tool Inc\Inventory\Stockroom", ComboBox1.Text)

        Stockkey = ReadKey("HKCU\Software\Tool Inc\Inventory\Stockroom")

        Dim result As Integer = MessageBox.Show("The application will need to close and re-open.  Click ok to continue", "Restart Needed", MessageBoxButtons.YesNo)
        If result = DialogResult.No Then
            Close()
        ElseIf result = DialogResult.Yes Then
            Application.Restart()
        End If
    End If
    Close()
End Sub

0 个答案:

没有答案