Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27375

VS 2010 Determin if background worker is finished before calling .RunWorkerAsync method again

$
0
0
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 it’s probably not the best way.

This is the code I’m thinking about using to test if not in use ( I know it’s 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()

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.

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

My project is becoming quite large and I’m 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 can’t miss any. This is a QC program

Thanks

Viewing all articles
Browse latest Browse all 27375

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>