Dim taskResults As IList(Of Task) = New List(Of Task)()
Try
For Each row As DataRow In filesTable.Rows
fileName = row("Name")
Dim request As FtpWebRequest = WebRequest.Create(Convert.ToString(ftp & ftpFolder) & fileName)
request.Method = WebRequestMethods.Ftp.DownloadFile
'Enter FTP Server credentials.
request.Credentials = New NetworkCredential("ksmusic", "Kevin2009")
request.UsePassive = True
request.UseBinary = True
request.KeepAlive = True
Try
taskResults.Add(Task.Factory.StartNew(Function()
Dim response As FtpWebResponse = request.GetResponse()
contentStream = response.GetResponseStream()
mailMessage.Attachments.Add(New Attachment(contentStream, fileName))
End Function))
Catch ex As Exception
Dim err As String = ex.Message
End Try
Next row
我遇到以下错误:- 在上一个呼叫仍在进行中时无法重新调用BeginGetRequestStream / BeginGetResponse。 有时我得到:-远程服务器返回错误:(530)未登录。
请让我知道如何管理并发。
谢谢