BITS工作没有充分理由就被取消了

时间:2012-02-20 13:47:24

标签: vb.net service jobs microsoft-bits

我创建了一个Windows服务,用于将文件从客户端上传到具有共享权限的服务器上的共享文件夹,每个人都可以使用Microsoft BITS服务完全控制它,此服务使用本地系统帐户运行。问题是BITS工作总是被取消,我不知道为什么。如有任何帮助,将不胜感激。

我正在使用此代码

Try
            Using BITSManager = New System.Net.BITS.Manager
                For Each sItem In arrlDriversFilesUploadList
                    Using job = New System.Net.BITS.Job("UploadJob", Net.BITS.JobType.Upload)
                        Dim sRemoteFileName As String = String.Format("{0}\{1}", "\\RemoteServer\SharedFolder", "File.txt")
                        Dim sLocalFileName As String = String.Format("{0}\{1}", "C:\LocalLocation", "File.txt")
                        job.Files.Add(sRemoteFileName, sLocalFileName)
                        BITSManager.Jobs.Add(job)
                        job.NoProgressTimeout = 300 '5 Minutes
                        job.Resume()
                        Dim JobComplete As Boolean = False
                        Do Until JobComplete
                            System.Threading.Thread.Sleep(3000)

                            If job.State = System.Net.BITS.JobState.Transferred Then
                evntlg.WriteEntry("Job done")
                                    JobComplete = True
                            End If

                            If job.State = System.Net.BITS.JobState.Acknowledged Then
                evntlg.WriteEntry("Job done")
                                    JobComplete = True
                            End If

                            If job.State = System.Net.BITS.JobState.Error Then
                evntlg.WriteEntry("Job has error")
                                    JobComplete = True
                            End If

                            If job.State = System.Net.BITS.JobState.Cancelled Then
                evntlg.WriteEntry("Job cancelled")
                                    JobComplete = True
                            End If

                        Loop
                    End Using
                Next
            End Using

        Catch ex As Exception
            evntlg.WriteEntry(ex.Message)
        End Try

1 个答案:

答案 0 :(得分:0)

我弄明白,共享文件夹的安全权限未在远程服务器上设置,我做了,然后每件事情都顺利进行。