Dunque, form che esegue saltuarie letture di un file e che può chiudersi da sé al verificarsi di determinati eventi.
Però non voglio che si chiuda proprio mentre sta leggendo dei dati nel file file (su altro thread tramite BackgroundWorker, per cui devo essere certo che sia eseguito tutto), inoltre se non lo sta leggendo mentre si chiude... dopo la sua chiusura devo accertarmi che il file non sia stato aggiornato subito dopo.
codice:
' Il codice è inserito nell' evento FormClosing.........
If BW_LeggeFile.IsBusy Then
Do
Sleep(100)
Application.DoEvents()
Loop Until Not BW_LeggeFile.IsBusy
Else
'non lo sta leggendo, aspetto 4 secondi e controllo se è stato modificato
LastTime = Now
Do
Application.DoEvents()
Loop Until (Now - HHLastTime).Seconds > 4
BW_LeggeFile.RunWorkerAsync()
If BW_LeggeFile.IsBusy Then
Do
Sleep(100)
Application.DoEvents()
Loop Until Not BW_LeggeFile.IsBusy
End If
End If
Errore saltuario:
Unhandled Exception Error
System.InvalidOperationException: This BackgroundWorker is currently busy and cannot run multiple tasks concurrently.
at System.ComponentModel.BackgroundWorker.RunWorkerAs ync(Object argument)
at System.ComponentModel.BackgroundWorker.RunWorkerAs ync()
at PsHndWtchr.FrmPanel1.(Object , FormClosingEventArgs )
Eppure ho ben preventivato via codice che il BW potrebbe essere Busy, da dove si origina l' errore? Non lo vedo.