ImapClient StartMonitoring - Processor usage High

I am using Aspose to create an email client in my company, in my tests when using the “StartMonitoring” function of class “ImapClient” the use of the processor stays high for some time.

Below my code.
image.png (7.1 KB)

Constant processor usage:
image.png (12.3 KB)

Here, the sample source code:
NewVersionWeb.zip (9.6 KB)

In my tests I used my account in Microsoft Exchange. I have tested on other accounts, and this problem only occurs in some of them.

@luizgavauseall,

We were able to observe the issue with performance in this case and have forwarded the issue details to our Product team via issue id: EMAILNET-38879. We’ll update you here once there is some further information available in this regard.

@kashif.iqbal,

any news about this issue?

@luizgavauseall,

The issue is still under investigation by our Product team. We’ll update you here once there is a fix version or some information available in this regard.

@kashif.iqbal,

additionally, I left the process running to see how long it would decrease processor usage. After exactly 30 minutes the processor has slowed, but the “StartMonitoring” function no longer receives events when a new email arrives.
I noticed that there is a timeout error in Activity Logging.

Attached, Activity Logging generated.
Aspose.Email.IMAP_2017-12-21.zip (3.7 KB)

@luizgavauseall,

We have further logged your comments under the logged issue and will update you here once there is some further information available in this regard.

@kashif.iqbal,

any news about this issue?

@luizgavauseall,

Thank you for contacting Aspose support team again.

We have requested the product team for the status of this issue and will write back here soon once any feedback is received. We are sorry for the inconvenience caused in this regard.

@luizgavauseall,

This issue is under progress and product team has added some fixes in the latest version. You are requested to test the issue using latest version [Aspose.Email for .NET 18.1.0](https://downloads.aspose.com/email/net/new-releases/aspose.email-for-.net-18.1/5e3ccda76c5f4c56aa07da3e0a05df34) and share the feedback. We will evaluate the feedback and proceed further accordingly.

@kashif.iqbal,

The problem persists, nothing has changed, I upgraded my application to the requested version, when I started the “StartMonitoring” function the processor increased and was high for more than half an hour.

@luizgavauseall,

Thank you for the feedback. We will share this information with the product team for their reference.

The issues you have found earlier (filed as EMAILNET-38879) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by kashif.iqbal

@kashif.iqbal,

The initial error stopped, but the problem persists, I put 3 e-mail accounts (gmail, outlook and my company) running in competition with the active StartMonitoring event, at the beginning the processor stays stable, but after a while the processor goes back up, always using 50% of the processor.

The thread that increases processor usage is always that of Gmail.

Ps.: In three tests these times ranged from 40 to 80 minutes.

@luizgavauseall,

Could you please share your updated test code with us where all the 3 accounts are tested for this issue? We’ll look into it for investigating the issue further at our end.

@kashif.iqbal,

var threadReceber = new Thread(threadInfo =>
{
	using (var imapClient = new ImapClient(contaEmail.ServidorEntrada, contaEmail.PortaEntrada))
	{
		imapClient.Username = contaEmail.Login;
		imapClient.Password = contaEmail.RecuperarSenha();

		var evnt = new ManualResetEvent(false);

		#region FirstTime
		var builder = new ImapQueryBuilder();
		builder.SentDate.Greater(DataUltimaSincronizacao.ToUniversalTime(), DateComparisonType.ByDateTime);
		var query = builder.GetQuery();
		var pageInfo = imapClient.ListMessagesByPage(ImapFolderInfo.InBox, query, 15);
		var messages = pageInfo.Items.ToList();
		while (!pageInfo.LastPage)
		{
			pageInfo = imapClient.ListMessagesByPage(ImapFolderInfo.InBox, query, pageInfo.NextPage);
			messages.AddRange(pageInfo.Items);
		}
		if (messages.Any())
		{
			foreach (var imapMessageInfo in messages)
			{
				var mailMessage = imapClient.FetchMessage(imapMessageInfo.SequenceNumber);
				OnRecebeuEmail(mailMessage, imapMessageInfo.Date, imapMessageInfo.IsRead);
			}
		}
		#endregion
		imapClient.StartMonitoring(ImapFolderInfo.InBox, delegate (object sender, ImapMonitoringEventArgs e)
		{
			foreach (var imapMessageInfo in e.NewMessages.OrderBy(x => x.Date))
			{
				imapClient.SelectFolder(ImapFolderInfo.InBox);
				var mailMessage = imapClient.FetchMessage(imapMessageInfo.SequenceNumber);
				OnRecebeuEmail(mailMessage, imapMessageInfo.Date, imapMessageInfo.IsRead);
			}
			evnt.Set();
		});
		while (true)
		{
			evnt.WaitOne(TimeSpan.FromMinutes(1));
			evnt.Reset();
		}
	}
});
threadReceber.Start();

@luizgavauseall,

I have tested this code with a gmail account and analyzed the performance using Aspose.Email for .NET 17.11 and 18.3 both. Using the older version, the issue was re-produced and processor usage reached 50% constantly. However on the other hand with the latest version 18.3 processor usage is around 3% to 4% which is normal. Could you please analyze the scenario again and share the feedback? If still issue is there, please share some test mail account credentials which can be used to reproduce the scenario.

@kashif.iqbal,

I did the simulation in the attached video, the processor starts to increase to 40:25 of the video, but I put it full to see that nothing is done in the code, only the StartMonitoring.

I’m still running the project, it’s now 123 minutes, and the processor is still in the same 25% of the video.

Edit: I could not upload the video, attached has the link.zip (173 Bytes)

@luizgavauseall,

I have tried to download video from the given link but it does not provide any video. Only one pdf file is there which contains little tutorial about using OneDrive. Could you please provide this data using some other option for sharing files?

@kashif.iqbal,

updated link.zip (192 Bytes)

At this time: aspose.PNG (9.8 KB)