Question

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.

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top