我在我的应用程序代码中使用Exchange Services在应用程序UI上显示电子邮件列表。但是,它能够检索电子邮件列表。但是显示所有设置需要非常长的时间。如果我减少显示的电子邮件数量,则显示时间会减少。
public static List<EmailMsg> GetEmailListInFolder(string folderName)
{
var folderId = GetFolderId(folderName);
var service = GetExchangeService();
if (folderId != null)
{
var emails = new List<EmailMsg>();
var count = 0;
var findResults = service.FindItems(folderId, new ItemView(100));
foreach (var item in findResults.Items)
{
var emailPropertySet = new PropertySet(
BasePropertySet.FirstClassProperties,
new PropertyDefinitionBase[]{
new ExtendedPropertyDefinition(4115, MapiPropertyType.Binary)
});
var message = EmailMessage.Bind(service, item.Id, emailPropertySet);
emails.Add(new EmailMsg(folderName, count++, item.Id.UniqueId, message.Subject, message.DateTimeReceived.ToString("yyyy-MMM-dd HH:mm:ss"), ""));
}
return emails;
}
return null;
}
当我调试代码并发现在进行下一行之前,该行需要花费几秒钟的时间。
var message = EmailMessage.Bind(service, item.Id, emailPropertySet);
请给我建议一种减少电子邮件项目加载时间的方法。谢谢
答案 0 :(得分:0)
您将退回所有BasePropertySet.FirstClassProperties
!
您可能需要考虑更改此设置,以仅返回所需的属性。
来自msdn的FirstClassProperty列表:
Id
ParentFolderId
ItemClass
Subject
Sensitivity
Body
Attachments
DateTimeReceived
Size
Categories
Importance
InReplyTo
IsSubmitted
IsDraft
IsFromMe
IsResend
IsUnmodified
InternetMessageHeaders
DateTimeSent
DateTimeCreated
AllowedResponseActions
ReminderDueBy
IsReminderSet
ReminderMinutesBeforeStart
DisplayCc
DisplayTo
HasAttachments
Culture
EffectiveRights
LastModifiedName
LastModifiedTime
IsAssociated
WebClientReadFormQueryString
WebClientEditFormQueryString
ConversationId
Flag
InstanceKey
EntityExtractionResult
Sender
ToRecipients
CcRecipients
BccRecipients
IsReadReceiptRequested
IsDeliveryReceiptRequested
ConversationIndex
ConversationTopic
From
InternetMessageId
IsRead
IsResponseRequested
ReplyTo
References
ReceivedBy
ReceivedRepresenting
您正在加载附件。要避免这么大的负担,您可以:
仅当您在特定邮件上时才加载附件。
仅加载属性 与LoadPropertiesForItems 并获得附件名称,扩展名等信息,而没有获得真正的附件。