Search code examples
vb.netmultithreadingbackgroundworker

cast not valid when using backgroundworker


I have moved my codes from Form_Load to BackgroundWorker but it says 'Specified cast is not valid' , Uploaded Here : My Codes Image

    Private Sub FirstRunWorker_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles FirstRunWorker.DoWork
    Dim url1 As String = publicurl & "index.php"
    Dim datavillages1 As String = TGet("", url1, url1, My.Settings.useragent)
    If datavillages1.Contains("error") Then
        'ADD LOG
    Else
        wb.DocumentText = datavillages1
        While wb.ReadyState <> WebBrowserReadyState.Complete
            Application.DoEvents()
        End While
    End If
End Sub

in main its work but in backgroundworker not , thanks for help


Solution

  • thanks for your helps and answers , I fixed my problem with invoke ! now i can access any controls and functions

        Me.Invoke(New MethodInvoker(Function()
    'dosomething
                                            End Function))