The below code is being used to fetch email messages from an Exchange email account. When attempting to return message from an account containing 10 to 20,000 messages the processes continually slows and after roughly 1 hour the process never returns. It should be noted the problem was experienced while bench marking with an overpower Exchange server (46GB of RAM all SS drives) and that was tweaked to force a cache big enough to fit the entire database. The server and the machine were on the same network so latency was not an issue. The maxCount parameter was added to see if there was a sweet spot that might improve response but regardless of it’s value the issue remained. Any recommendations for optimization to improve throughput?
protected override MailInfoCollection download()
{
maxCount = 50;
MailInfoCollection emailList = new MailInfoCollection();
try
{
//this query is for returning only the unread
ImapQueryBuilder imapbuilder = new ImapQueryBuilder();
imapbuilder.HasNoFlags(ImapMessageFlags.IsRead);
Aspose.Email.MailQuery query = imapbuilder.GetQuery();
ImapMessageInfoCollection messageInfos = _client.ListMessages(query, maxCount);
if (messageInfos.Count > 0)
{
for (int i = 0; i < messageInfos.Count; i++)
{
ImapMessageInfo info = messageInfos[i];
MailMessage message = null;
try
{
//_client stays connect until all messages are retrieved.
message = _client.FetchMessage(info.SequenceNumber);
}
catch (Exception e){}
}
}
}
}