隱藏表單不會阻止後臺工作人員 - 實際上關閉表單不會阻止它 - 表單將等待後臺工作人員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
可以發佈一個類似你所指的隱藏事件嗎? – Paparazzi 2013-04-22 20:49:29
它是這樣的:在Form1裏面的Form1我有backgorundWorker。如果用戶按取消按鈕,則隱藏Form1。如果用戶按其他窗體上的任何添加,編輯按鈕讓我們說Form2,它創建Form1的新實例並關閉舊的.backgorundWorker被稱爲OnLoad – SOAMad 2013-04-22 20:50:50
定義你想要的問題。首先它是隱藏的,現在取消OnLoad。 – Paparazzi 2013-04-22 21:01:08