.net - 在VB.NET中调用hide方法后我可以使用backgroundWorker吗

标签 .net vb.net sqlite backgroundworker vb.net-2010

我有一个关于后台工作人员的简单问题。我从未使用过它,所以我不知道它是如何工作的。
我正在使用 VB.NET Express 2010。
我只想在表单的 backgroundWorker 中进行数据库监控。

以下是我想要实现的几件事。

  • 使用 select 语句监控 SQLite DB 文件。
  • 从数据库中提取数据并将它们放入变量中。
  • 比较具有特定条件的值,如果匹配,则将值传递给另一个表单并调用它。
  • 继续监控。
  • 我希望后台工作人员在表单的 form.hide() 时执行此操作方法被调用。

  • 请给出您宝贵的答复,如果我不是正确的方法,请建议另一种方法。

    最佳答案

    隐藏表单不会停止后台 worker ——实际上关闭表单不会停止它——表单会等待后台 worker 的 isBusy 属性报告 false 后再继续。

    更新以回应新评论

    您可能最好使用计时器并将其他工作卸载到新线程,请参见下面的示例。如果操作尚未完成,则 If _worker is nothing将停止重新启动操作。一定要设置_worker = nothing在你的过程结束时,这个工作虽然。

    此外,我刚刚快速输入了此内容,它可能无法开箱即用,但应该为您提供一个起点。

    Imports System.Threading
    
    Public Class Form1
    
        Dim _worker As Thread
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            Timer1.Interval = 10000
            'interval in milliseconds so 1000ms = 1 second / above 10000 = 10 seconds
    
            Timer1.Enabled = True
            Timer1.Start()
    
        End Sub
    
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
            StartWorkerThread()
        End Sub
    
        Private Sub StartWorkerThread()
    
            If _worker Is Nothing Then
                _worker = New Thread(AddressOf myWorker)
                _worker.Start()
    
    
            End If
    
        End Sub
    
        Private Sub myWorker()
            'do your work here...use an event or a delate to fire another sub/function on the main thread if required
    
                'when finished
                _worker = nothing
                'Important! This will allow the operation to be started again on the timer tick
            End Sub
    
        End Class
    

    关于.net - 在VB.NET中调用hide方法后我可以使用backgroundWorker吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16155871/

    相关文章:

    .net - WM_DESTROY、WM_CLOSE绕过IMessageFilter

    .net - 我在哪里可以看到 ASP.NET 2.0 Web 项目中的引用和 Web 引用列表

    c# - 当 "Unable to read file"html 文件与 Excel 时,IE 中的 "Open"错误,但不是当 "Save"首先

    mysql - 将 SQL 数据插入 VB 数据库

    ios - 在 Swift 中显示来自 SQLite Blob 的图像

    python - 在执行后续语句之前,如何等待函数的返回值,该函数使用 tkinter GUI 并接受用户的输入

    c# - gacutil 和环境中的次要版本差异导致严重问题

    .net - .NET 可以使用哪些 HMM(隐马尔可夫模型)压缩库?

    c++ - 通过*.dll 文件调用*.exe 文件并提交参数

    ruby-on-rails - Heroku 尝试在每次部署时安装 sqlite