0

I'm trying to use MS BITS (Background Intelligent Transfer service) to upload files from many computers to a server, but the only useful example I read was in StackOverFlow, and here it is:

Imports SharpBits.Base         
Using b As New BitsManager()
     mynewjob = b.CreateJob("jobname", JobType.Upload)
     mynewjob.AddFile("\\ServerName\BitsUploads\File.txt", "C:\File.exe")
     mynewjob.Resume()
End Using

but frankly, I don't know how to handle the whole thing about BITS jobs management, and I could not find a complete example demonstrate how the management will be so, please I need help about that.

Volkmar Rigo
  • 1,158
  • 18
  • 32
Ahmed Nazmy
  • 391
  • 1
  • 8
  • 20

1 Answers1

0

Finally I found the answer, Simply, First, add JobProgressTimeout to some value. Second, put your code in a loop to keep checking the status of the BITS job execution just like that:

    Dim oJobStatus As System.Net.BITS.JobState = 0
    oJobStatus = sJobStatus

    Try
        If oJobStatus = System.Net.BITS.JobState.Transferred Then
            MsgBox("Job transfered")
            Return True
        End If

        If oJobStatus = System.Net.BITS.JobState.Acknowledged Then
            MsgBox("Job transfered")
            Return True
        End If

        If oJobStatus = System.Net.BITS.JobState.Error Then

            MsgBox("Job cancelled")
            Return True
        End If

        If oJobStatus = System.Net.BITS.JobState.Cancelled Then
            MsgBox("Job cancelled")
            Return True
        End If

        Return True
    Catch ex As Exception
        msgbox(ex.Message)
        Return True
    End Try
Ahmed Nazmy
  • 391
  • 1
  • 8
  • 20