我必須在任何表上顯示很多事務。處理需要很長時間。 我想在visual basic 2010中使用後臺進程,但它總是會提供一個類似於「檢測到跨線程操作」的錯誤消息。我嘗試了很多我在互聯網上找到的方式,但仍然無法找到問題所在。 請幫我解決這個問題。 這是我的代碼:使用後臺工作VB.NET
Private Sub CHK_A_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CHK_A.CheckedChanged
Disabled()
P_Panel.Visible = True
B_Worker.RunWorkerAsync()
End Sub
Private Sub BTN_Search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_Search.Click
USP_Select_Registration()
End Sub
Private Sub B_Worker_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles B_Worker.DoWork
Threading.Thread.Sleep(25)
USP_Select_Registration()
End Sub
Private Sub B_Worker_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles B_Worker.RunWorkerCompleted
P_Panel.Visible = False
End Sub
這一個是我的存儲過程
Public Sub USP_Select_Registration()
Dim Con As New SqlConnection(SQLCon)
Try
Con.Open()
Dim Cmd As New SqlCommand("USP_Select_Registration", Con)
Cmd.CommandType = CommandType.StoredProcedure
Cmd.Parameters.Add("@Check", SqlDbType.Bit).Value = CHK_A.EditValue
Cmd.Parameters.Add("@Month", SqlDbType.Int).Value = CBO_Month.SelectedIndex + 1
Cmd.Parameters.Add("@Year", SqlDbType.Int).Value = SPE_Year.EditValue
Cmd.Parameters.Add("@Search", SqlDbType.VarChar, 150).Value = TXT_Search.Text
DS_Registration.Tables("MST_Registration").Clear()
Dim Adt As New SqlDataAdapter(Cmd)
Adt.Fill(DS_Registration.Tables("MST_Registration"))
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
Finally
Con.Close()
End Try
End Sub
我是爲英語不好 – christ2702
'昏暗的工人作爲BackgroundWorker'在DoWork的抱歉..嘗試刪除或使其作爲註釋 – matzone
它給出了同樣的錯誤 – christ2702