我已經構建了一個程序來檢查應用程序是否啓用。如果啓用,它將執行BackgroundWorker
,如果不啓用,它將通知用戶並立即關閉。它適用於我的電腦,但對其他人來說,它不會沒有錯誤地完成代碼。程序不能在不同的設備上工作
這裏是我的代碼:
Dim Status As String = ""
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
If Status = "Enabled" Or Status = "Disabled" Then
Else
Status = WebBrowser1.Document.GetElementById(Account & "Flag").InnerText.ToString
If Status = "Enabled" Then
BackgroundWorker1.RunWorkerAsync()
ElseIf Status = "Disabled" Then
MessageBox.Show("Disabled", "System", MessageBoxButtons.OK)
Close()
Else
Status = ""
End If
End If
End Sub
對於我來說,我認爲它不會做的工作開始BackgroundWorker
。我已經通過在代碼的第一行之後放置MsgBox("Code 1 Success")
以及在第二行代碼之後放置MsgBox("Code 2 Success")
等來測試代碼。它到達BackgroundWorker1.RunWorkerAsync()
代碼,但它不會在BackgroundWorker下執行代碼。
這裏是BackgroundWorker1代碼:
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
Label1.Text = "Status: Checking"
Label1.ForeColor = Color.FromKnownColor(KnownColor.Highlight)
Try
Dim mysqlconnection As MySqlConnection = New MySqlConnection("server=85.10.205.173;port=3306;username='" & User & "';password='" & Pass & "'")
Dim mysqlcommand As MySqlCommand = Nothing
Dim mysqldatareader As MySqlDataReader = Nothing
mysqlconnection.Open()
Using table As DataTable = New DataTable
Using command As MySqlCommand = New MySqlCommand("Select * from login.accounts where Username = 'Jake';", mysqlconnection)
Using adapter As MySqlDataAdapter = New MySqlDataAdapter(command)
adapter.Fill(table)
End Using
End Using
For Each row As DataRow In table.Rows
If row("Flag") = "enable" Then
Label1.Text = "Status: Enabled"
Label1.ForeColor = Color.Green
Button1.Enabled = False
Button2.Enabled = True
ProgressBar1.Visible = False
Else
Label1.Text = "Status: Disabled"
Label1.ForeColor = Color.OrangeRed
Button1.Enabled = True
Button2.Enabled = False
ProgressBar2.Visible = False
End If
Next
End Using
mysqlconnection.Close()
Catch ex As Exception
Threading.Thread.Sleep(1000)
Label1.Text = "No Internet Connection"
End Try
End Sub
我知道,它並沒有達到這個代碼,因爲Label1.Text
沒有改變,如果達到這部分代碼就一定是「狀態:檢查「。
我的代碼有什麼問題?再次,它在我的電腦中工作,但對其他人來說,它不是。任何幫助是極大的讚賞!
所以應的代碼是什麼呢?我不知道該怎麼做。該代碼完美地運行我的電腦,但打開到另一個不會執行backgroundworker。我很困惑 –
你檢查鏈接了嗎? – sallushan
是的。但我無法理解它。 –