Problem je sledeci. Napisao sam metod koji salje mailove sa atachmentom koji u glavnom sadrzi HTML. Program radi treba da salje recimo 10 mailova i svaki attachment je razlichit, sto znachi:
Ako program salje fajl od recimo 2 megabajta, ostali sitni fajlovi(html) ne bi trebalo da chekaju da se ovaj posalje nego da rade asinhrono tj
da se "istovremeno" posalju. To sam "odradio" sa delegatima. ALI (uvek ovo ali)

EVO coda (prvo za mali fajl)
Ovako pozivam method klase smtp:
Code:
Smtp123.Smtp1 smtp = new Smtp123.Smtp1();
string ttmlString = "<HTML><HEAD><TITLE>Test</TITLE></HEAD><BODY>bla bla bla bla</BODY></HTML>";
ArrayList Html = new ArrayList();
smtp.SendEmailAsync(Html, "g:\\mailerOgi.config");
Smtp123.Smtp1 smtp = new Smtp123.Smtp1();
string ttmlString = "<HTML><HEAD><TITLE>Test</TITLE></HEAD><BODY>bla bla bla bla</BODY></HTML>";
ArrayList Html = new ArrayList();
smtp.SendEmailAsync(Html, "g:\\mailerOgi.config");
Zatim u klasi Smtp1 method za slanje i delegat su de3finisani ovako:
Code:
public delegate string SendEmailDelegate(string configFile,ArrayList HtmlAttachments);
private void GetResultsOnCallback(IAsyncResult ar)
{
string result;
SendEmailDelegate del = (SendEmailDelegate)((AsyncResult)ar).AsyncDelegate;
try
{
result = del.EndInvoke(ar);
Console.WriteLine();
}
catch (Exception ex)
{
result = ex.Message;
}
}
/// <summary>
/// Method sends mail, if mail sent it returns "ok"
/// </summary>
/// <param name="HTMLAttachments">represent array list of Html that will be sent like attachment</param>
/// <param name="configFile">represent config file with data: from, to, cc, bcc, server, subject</param>
/// <returns></returns>
public string SendEmailAsync(ArrayList HTMLAttachments, string configFile)
{
try
{
SendEmailDelegate dc;
dc = new SendEmailDelegate(this.SendIT);
AsyncCallback cb = new AsyncCallback(this.GetResultsOnCallback);
IAsyncResult ar = dc.BeginInvoke(configFile, HTMLAttachments, cb, null);
//Thread.Sleep(5000);
return ("ok");
}
catch (Exception ex)
{
return ex.Message;
}
}
private string SendIT(ArrayList HTMLAttachments, string configFile)
{
///ovde saljem smtp serveru potrebne podatke
}
public delegate string SendEmailDelegate(string configFile,ArrayList HtmlAttachments);
private void GetResultsOnCallback(IAsyncResult ar)
{
string result;
SendEmailDelegate del = (SendEmailDelegate)((AsyncResult)ar).AsyncDelegate;
try
{
result = del.EndInvoke(ar);
Console.WriteLine();
}
catch (Exception ex)
{
result = ex.Message;
}
}
/// <summary>
/// Method sends mail, if mail sent it returns "ok"
/// </summary>
/// <param name="HTMLAttachments">represent array list of Html that will be sent like attachment</param>
/// <param name="configFile">represent config file with data: from, to, cc, bcc, server, subject</param>
/// <returns></returns>
public string SendEmailAsync(ArrayList HTMLAttachments, string configFile)
{
try
{
SendEmailDelegate dc;
dc = new SendEmailDelegate(this.SendIT);
AsyncCallback cb = new AsyncCallback(this.GetResultsOnCallback);
IAsyncResult ar = dc.BeginInvoke(configFile, HTMLAttachments, cb, null);
//Thread.Sleep(5000);
return ("ok");
}
catch (Exception ex)
{
return ex.Message;
}
}
private string SendIT(ArrayList HTMLAttachments, string configFile)
{
///ovde saljem smtp serveru potrebne podatke
}
E ako pozovem funkciju SendEmailAsync sa onim malim html=om, program radi. Medjutim ako ostane isti code (znachi iskometarisani sleep) a promenim htmlstring recimo oko 200 redova html-a, i jos funkciju pozovem 3 puta za redom, nece da radi. Ali ako odkomentarishem Sleep sto znachi da je u upotrebi program radi super.
E sada ako se sleep pstavi kao sto sam rekao odkomentarisan a salje se mali fajl, program opet samo izadje i nece da radi.
Nadam se da me neko razumeo. Pa ako neko zna zasto se ovo desava ima PIVO
