在我的 Windows 窗体中,我有这个查询可以处理大约 2,000,000 行。执行查询会冻结界面,大约需要 60 秒才能完成。
有没有办法可以放置一个进度条来通知用户任务正在进行中?
我是多线程的新手,所以任何帮助将不胜感激。
这是需要时间的代码:
在 cmd.executenonquery() 处冻结断点
Public Sub InsertNumberswithMsgID(ByVal messageID As Integer, ByVal tableName As String)
Dim cmd As SqlCommand = Nothing
Try
cmd = New SqlCommand(("dbo.[InsertNumbers_withMsgID]"), cn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@tablename", tableName)
cmd.Parameters.AddWithValue("@msgid", messageID)
cmd.CommandTimeout = 6000
If Not cn Is Nothing And cn.State = ConnectionState.Closed Then cn.Open()
cmd.ExecuteNonQuery()
Catch ex As SqlException
Catch ex As Exception
Finally
If Not cn Is Nothing And cn.State = ConnectionState.Open Then cn.Close()
If Not cmd Is Nothing Then cmd.Dispose()
End Try
End Function