Backgroundworker doesn't works in my vb.net application

Hakan
Hakan used Ask the Experts™
on
I'm trying to use background worker but i didn't succeeded. It didin't perform anything. I'm a bit newbie about background worker topic.

So i'll be glad for any help. Thanks.

This is RunWorkerAsync() when i clicked my run button.
    Private Sub CheckRun(sender As Object, e As EventArgs) Handles cmdModuleCheck_run.Click
        bgWorkCheck.RunWorkerAsync()
    End Sub

Open in new window


This is .DoWork() i'm calling it from another class
    Private Sub DoWorkCheck(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles bgWorkCheck.DoWork
        ModuleCheck.LocalTools.RunCheck(Globals.SpckModel)
    End Sub

Open in new window


This is my DoWork code which i runned from another class.
 Public Shared Sub RunCheck(ByVal mdl As IScrModel)

            Dim tView As TreeView = GUI.treCheckListMain
            Dim dgView As DataGridView = GUI.dgvCheckInfo
            dgView.Rows.Clear()

            For Each nodeParent As TreeNode In tView.Nodes
                For Each nodeChild As TreeNode In nodeParent.Nodes
                    If nodeChild.Checked = True Then
                        dgView.Rows.Add(nodeParent.Text, nodeChild.Text, "In queue")
                    End If
                Next
            Next

            If tView.Nodes.Item("nodBody").Nodes.Item("nodBodyComp").Checked = True Then
                Dim rowIndex As Integer = FindRowDgv(tView.Nodes.Item("nodBody").Text, tView.Nodes.Item("nodBody").Nodes.Item("nodBodyComp").Text)
                Try
                    StyleStatus(rowIndex, "Performing", Color.Yellow)
                    Body.ListBodies(mdl, GUI.GetRecursive(GUI.cboCheckBodyComputed_recur.SelectedIndex), GUI.dgvCheckBodyComputed)
                    StyleStatus(rowIndex, "Finished", Color.Green)
                Catch ex As Exception
                    StyleStatus(rowIndex, "Error Occured", Color.Red)
                    Tools.OutputLog.Print(Tools.OutputLog.Type.ERR, ex.Message)
                End Try

            End If
            If tView.Nodes.Item("nodMarker").Nodes.Item("nodMarkerComp").Checked = True Then
                Dim rowIndex As Integer = FindRowDgv(tView.Nodes.Item("nodMarker").Text, tView.Nodes.Item("nodMarker").Nodes.Item("nodMarkerComp").Text)
                Try
                    StyleStatus(rowIndex, "Performing", Color.Yellow)
                    Marker.ListMarkers(mdl, GUI.GetRecursive(GUI.cboCheckMarkerPosition_recur.SelectedIndex), GUI.dgvCheckMarkerPosition)
                    StyleStatus(rowIndex, "Finished", Color.Green)
                Catch ex As Exception
                    StyleStatus(rowIndex, "Error Occured", Color.Red)
                    Tools.OutputLog.Print(Tools.OutputLog.Type.ERR, ex.Message)
                End Try

            End If
        End Sub

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior .Net Consultant
Top Expert 2016
Commented:
It looks like your RunCheck are trying to access a treeview and a datagrid from a form on a different thread. Is that possible? They are surely empty.
            Dim tView As TreeView = GUI.treCheckListMain
            Dim dgView As DataGridView = GUI.dgvCheckInfo

Open in new window


Is the very same code without the BGW (calling RunCheck directly from your Click event) is working fine? You will most probably need to pass the data of these controls to your method. And you better forget about setting properties of these controls from your RunCheck.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial