I have a background work that copies files from one folder to another. Sometimes the files to be copied can be rather large and sometimes the background worker .RunWorkerAsync method will be need to called again before the previous batch of files has finished copying. I need to find a reliable way to determine that the background worker is not in use before trying to call it again.
The way I thought of was to create a do until loop to test if background worker is in use and when the background worker is no longer in use then call the RunWorkerAsync method again to do my next file copy. This is the only way I could think of to test if the background worker was in use and I know its probably not the best way.
This is the code Im thinking about using to test if not in use ( I know its probably not the best):
This is the code I currently have for the background worker. I do some other things in the procedure but the main thing I need to do to copy the files.
My project is becoming quite large and Im getting quite a bit of code so before I start messing around with trying to detect the inuse, I would prefer some ideas the best way to do this. I have to make sure every group of files is copied and I cant miss any. This is a QC program
Thanks
The way I thought of was to create a do until loop to test if background worker is in use and when the background worker is no longer in use then call the RunWorkerAsync method again to do my next file copy. This is the only way I could think of to test if the background worker was in use and I know its probably not the best way.
This is the code Im thinking about using to test if not in use ( I know its probably not the best):
Code:
Do Until BgWrkSyncDrv1CopyTimer.IsBusy = False
'Do nothing here because if must be busy
but I have to wat because I have to have these files
Loop
'If I get to this point then it must no longer be busy
Me.BgWrkSyncDrv1CopyTimer.RunWorkerAsync()
Code:
Private Sub BgWrkSyncDrv1CopyTimer_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BgWrkSyncDrv1CopyTimer.DoWork
Me.lblDisplayDrive1.BackColor = Color.Green
Me.vBNDr1InUse = True
HDISettings.CopyLostDrv1Files(Me.txtCopyTo1.Text)
Me.vBNDr1InUse = False
Me.lblDisplayDrive1.BackColor = Color.Transparent
End Sub
Thanks