Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
tsereg  
#1 Posted : Thursday, July 18, 2013 5:05:30 AM(UTC)
tsereg

Rank: Newbie

Groups: Registered
Joined: 7/18/2013(UTC)
Posts: 0
Croatia
Location: Zagreb

Thanks: 1 times
The example for using EASendMail SMTP component asynchronously demonstrates using AsyncWaitHandle to block execution until the SendMail operation completes, like this:

SmtpClientAsyncResult oResult = oSmtp.BeginSendMail(oServer, oMail, null, null);
while (!oResult.IsCompleted) {
oResult.AsyncWaitHandle.WaitOne(50, false);
}
oSmtp.EndSendMail(oResult);


Is it possible to use callback delegate? I have tried to use the code like following:

SmtpClientAsyncResult oResult = oSmtp.BeginSendMail(oServer, oMail, 
new AsyncCallback(AsyncSendCompletedCallback), oSomeStateObject);

//...

private void AsyncSendCompletedCallback(IAsyncResult result)
{
try
{
EASendMail.SmtpClientAsyncResult ar = result as EASendMail.SmtpClientAsyncResult;
ar.SmtpClientInstance.EndSendMail(ar);
}
catch( EASendMail.SmtpTerminatedException )
{
}
catch( Exception ex )
{
}
}


This works fine when communication with SMTP completes without problems. If there is a communication error, however, the operation will never complete, i.e. callback procedure seems to newer get called. For example, if wrong password is set, the opeation continues and various events are raised as expected, until the SMTP server responds with status code 535 Bad authentication. Then everything stops, and the callback procedure is never called. This does not happen when AsyncWaitHandle is used.

Can you confirm that callback delegate method is actually supported?
ivan  
#2 Posted : Thursday, July 18, 2013 6:20:51 AM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,153

Thanks: 9 times
Was thanked: 55 time(s) in 55 post(s)

Thank you very much for reporting this problem, after I double-checked the code, it is a bug in the callback. In current version, the callback delegate is not invoked if there is an exception.

I will send you a quick fix at tomorrow.

Thanks again.
thanks 1 user thanked ivan for this useful post.
tsereg on 7/18/2013(UTC)
tsereg  
#3 Posted : Thursday, July 18, 2013 6:28:38 AM(UTC)
tsereg

Rank: Newbie

Groups: Registered
Joined: 7/18/2013(UTC)
Posts: 0
Croatia
Location: Zagreb

Thanks: 1 times
Thanks for the very quick reply.

I have temporarily cirumvented the problem by using BackgroundWorker as follows:
bwWaitAsync = new BackgroundWorker();
bwWaitAsync.DoWork += bwWaitAsync_DoWork;
bwWaitAsync.RunWorkerCompleted += bwWaitAsync_RunWorkerCompleted;

//...

bwWaitAsync.RunWorkerAsync(oSmtp.BeginSendMail(oServer, oMail, null, oSomeStateObject));

//...

void bwWaitAsync_DoWork(object sender, DoWorkEventArgs e)
{
EASendMail.SmtpClientAsyncResult result = e.Argument as EASendMail.SmtpClientAsyncResult;
result.AsyncWaitHandle.WaitOne();
e.Result = result;
}

void bwWaitAsync_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
AsyncSendCompletedCallback(e.Result as EASendMail.SmtpClientAsyncResult);
}


This is not the optimal solution as it creates one more thread, but works fine.

So, there is no rush to fix the bug, I can wait until the next regular release.

Thank you again!

Edited by user Thursday, July 18, 2013 6:31:59 AM(UTC)  | Reason: Not specified

ivan  
#4 Posted : Thursday, July 18, 2013 6:52:59 AM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,153

Thanks: 9 times
Was thanked: 55 time(s) in 55 post(s)

Hi, I have sent you a quick fix by private message, you can download and test it.
If it is ok, please kindly let me know, then i can add this fix at next release.

Thank you very much
tsereg  
#5 Posted : Thursday, July 18, 2013 7:20:44 AM(UTC)
tsereg

Rank: Newbie

Groups: Registered
Joined: 7/18/2013(UTC)
Posts: 0
Croatia
Location: Zagreb

Thanks: 1 times
In my development environment, using first a wrong password, and then an unexisting host, EASendMail40.dll worked as expected, errors being reported as exceptions from EndSendMail.

I will be deploying the program at one site tomorrow, and will have it run experimentally during the next week. Will report if any issues arrise.

Thank you, and greetings!

ivan  
#6 Posted : Sunday, July 28, 2013 5:15:25 AM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,153

Thanks: 9 times
Was thanked: 55 time(s) in 55 post(s)

Just let you know, we just released 7.0.0.2, this version includes the fix for callback.
Users browsing this topic
Guest (2)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.096 seconds.

EXPLORE TUTORIALS

© All Rights Reserved, AIFEI Software Limited & AdminSystem Software Limited.