Using version 3.6.0.0 of Aspose.Email on .NET 4.0 the program encounters an unhandled IOException occasionally.
The stack trace reported by Windows Error Reporting (WER) is:
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.IOException
Stack:
at System.Net.Security._SslStream.ProcessWrite(Byte[], Int32, Int32, System.Net.AsyncProtocolRequest)
at System.Net.Security.SslStream.Write(Byte[], Int32, Int32)
at ..Flush()
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Threading.ThreadHelper.ThreadStart()
Note that the code and thread using AsposeEmailClient is not getting this exception.
The error stack appears to indicate the occurred in the context of an asynchronous operation that is calling Flush().
We are not explicitly using asynchronous calls such as BeginConnect/EndConnect, BeingSelectFolder/EndSelectFolder etc.
The ImapClient is used in the following way:
///This code runs periodically every couple of minutes.
try {
if(Connect()) {
_imapClient.SelectFolder(_inboxFolderName, false);
_imapClient.ListMessages();
}
}
catch(Exception exception) {
LogTheException(exception);
}
public bool Connect() {
try {
if (_imapClient != null && _stopwatch.Elapsed.TotalMinutes < ImapConnectionExpirationPeriodInMins) {
return true; //ImapConnectionExpirationPeriodInMins is 30 minutes
}
if (_imapClient != null)
Disconnect(emailStoreProcessing);
_imapClient = new ImapClient { Host = _serverName, Port = _portNumber, Username = _userName, Password = _password, SecurityMode = ImapSslSecurityMode.Implicit, EnableSsl = true, Timeout = Timeout };
_imapClient.Connect(true);
return true;
catch (Exception exception) {
DumpStack(LogPrefix + "Connect() encountered exception: " + exception.Message, exception); return false;
}
}
public void Disconnect()
{
if (debug) Log(LogPrefix + "Imap Disconnect() Begin...");
if (_imapClient != null) {
try {
_imapClient.Disconnect();
}
catch (Exception e) {
DumpStack(LogPrefix + "Disconnect() encountered exception: " + e.Message, e);
}
finally {
_imapClient.Dispose();
_imapClient = null;
}
}
if (debug) Log(LogPrefix + "Disconnect() Done...");
}
Note: this works most of the time, but periodically there is an unhandled IOException causing the process to terminate.
Note: It also seems that this error may not have been occurring originally when using version 1.2.0.0 of Aspose.Email and .NET 2.0.
Does Flush() get called asynchronously?
What is the recommendation for recycling IMAP connections using a ImapClient object? Presently we are getting a new connection (after disconnecting) every 30 mins, is that too frequent or perhaps not frequent enough?