sql-server - 如何在 VB NET 函数中正确地在某个时间间隔(定时器)刷新 SQL Server 中的数据
问题描述
我有一些代码用于每 5 秒检查一次来自 sql server 的数据。它实际上很好,但我看到内存使用量增长缓慢?什么会导致这种情况?
这是简单的代码:Public LastID as integer=0 Public NewID as integer=0
Private Sub Timer1_Tick(sender As Object, e As EventArgs) 处理 TimerSken.Tick
Dim com As New SqlCommand("Select * from Products where datediff(second,FinishedDate, GETDATE())<7 order by ID desc", Connection)
Dim ad As New SqlDataAdapter(com)
Dim tableTimer As New DataTable()
ad.Fill(tableTimer)
If tableTimer.Rows.Count = 0 Then
Return
End If
NewID = tableTimer.Rows.Item(0)("ID")
If LastID <> NewID Then
Dim Tittle As String = tableTimer.Rows.Item(0)("Operator").ToString & ", " & tableTimer.Rows.Item(0)("FinishedDate").ToString
Dim text As String = tableTimer.Rows.Item(0)("Customer").ToString & ", " & tableTimer.Rows.Item(0)("WorkID").ToString & vbNewLine & tableTimer.Rows.Item(0)("Product").ToString & ", " & tableTimer.Rows.Item(0)("Operation").ToString
LastID = NewID
Notification.Show(Me, info.Caption = Tittle, info.Text = text)
End If
End Sub
我把所有这些都放在计时器里可以吗?
解决方案
推荐阅读
- flutter - 如何制作一个像这样推动另一个屏幕的屏幕?(例如:不和谐的应用程序)
- python - 将大型 PostgreSQL 表读入 Pandas 数据框时出现问题
- rust - 一个以 trait 作为参数的 Rust 闭包
- android - 将我的颤振应用程序添加到 android 中的超省电模式
- c++ - 用 C++ 编译 ImGui
- docker - 为什么 Docker 守护进程无法访问 localhost 地址?
- machine-learning - 如何将 MultiOutputClassifier 应用于 Naive-Bayes 算法的数据集
- parallel-processing - 并行运行地图切片
- r - 如何根据R中第二个变量的排名将变量的排名分成小数,以打破平局
- mongodb - 如何高效地执行多个 MongoDB 查询,每次都删除搜索参数?