我正在编写一些代码以下载和处理电子邮件附件并处理它们。代码在某些情况下按要求工作,但仍有一些主要问题。Exchange Web Services附件加载速度慢
每当代码加载安装到本地磁盘上的文件,它需要很长的时间这样做,并且经常超时除了具有以下不同的下载速度慢的结果:
A first chance exception of type 'Microsoft.Exchange.WebServices.Data.ServiceRequestException' occurred in Microsoft.Exchange.WebServices.dll
我可能是错的,但是如果有问题的交换服务器与运行代码的服务器在同一个千兆网络上,并且outlook可以快速访问电子邮件,附件等,那么附件的下载速度应该比现在快得多,而且要持续得多。下面是下载/加载时间的一些例子:
- 800KB邮编 - 100万4S
- 840KB邮编 - 6米18S
- 1.33MB邮编 - 11米23S
- 2.78MB邮编 - 17米3S
我已经尝试将EWS连接超时设置设置为300000ms而不是默认的100000ms,以使附件有更多时间下载,异常数量略有下降,但等待时间现在太长了。
代码确实以线程运行,一次不超过8个(我认为EWS的限制是10个),但我无法想象这会产生很大的差异。 (当我一次测试单个电子邮件时,它还没有完成)。
这里是线程代码,下载附件(为简单起见去掉了一些不相关的位):
Dim strMessageFolder As String
' Prepare the directory where this emails attachments will be stored
strMessageFolder = g_strFolder_Temp & strMessageID & "\"
' Create a folder to store the attachments for this email
Call FileSystem_CreateFolder(strMessageFolder, True)
' Process the emails attachments
For Each emailAttachment In emailMessage.Attachments
Dim fileattach As FileAttachment
'Dim fileattachStream As FileStream
Dim strAttachmentFile As String
' Prepare for the downloading of the attachment
fileattach = emailAttachment
blnTryFailed = False
intAttempts = 0
strAttachmentFile = strMessageFolder & fileattach.Name
' Handle up to 3 download attempts
Do
Try
' Try to download the attachment - Method 1
fileattach.Load(strAttachmentFile)
' Try to download the attachment - Method 2
'fileattachStream = New FileStream(strAttachmentFile, FileMode.OpenOrCreate, FileAccess.ReadWrite)
'fileattach.Load(fileattachStream)
'fileattachStream.Close()
'fileattachStream.Dispose()
blnTryFailed = False
Catch ex As Exception
blnTryFailed = True
' Ensure the failed download is deleted
Call FileSystem_DeleteFile(strAttachmentFile)
intAttempts += 1
End Try
Loop While blnTryFailed And intAttempts < 3
' If the attachment download was unsuccessful then we cannot process the current email
If blnTryFailed = True Then
emailMessage.IsRead = False
'message.Subject = message.Subject & " - Attachment download failed, skipped"
Try
emailMessage.Update(ConflictResolutionMode.AutoResolve)
Catch ex As Exception
Call Logging_Add("Unable to mark email as skipped", strMessageID, "Debug")
End Try
Exit Sub
End If
正如前面提到的,即时了解Exchange限制,但在无法找到相关的速度什么哪些附件被下载。 所以我的问题是什么可能导致如此慢的下载速度?