Home > Net >  My project, back-end code email why not in real time
My project, back-end code email why not in real time

Time:09-23

Public void ExecuteTask ()
{
Try
{
//get all the need to deal with the task of
Var list=WBLL. GetToGoTasks (EmailConfig. RetryTimes, EmailConfig RetryPeriod);
If (a list!=null & amp; & List. The Count & gt; 0)
{
The Info (" ExecuteTask Started at "+ DateTime. Now. The ToString (" MM - dd yyyy - HH: MM: ss"));
//if the number of jobs is greater than the number of threads, according to the number of threads allocated
If (list. Count & gt; ThreadCount)
{
Int pageSize=list. Count/ThreadCount,
Rest=list. Count % ThreadCount;
//to the child thread assigned
for (int i=0; i {
Try
{
ParameterizedThreadStart PTS=new ParameterizedThreadStart (ExecuteInThread);
Thread th=new Thread (PTS);
List Param=new List (a);
if (i !=ThreadCount - 1)
{
Param=list. Skip (I * pageSize.) Take (pageSize). ToList ();
}
The else
{
//the last thread to run the remainder
Param=list. Skip (I * pageSize.) Take (pageSize + rest) ToList ();
}
Th. Start (param);
}
The catch (Exception ex)
{
The log. The Error (" Allot the Task by Thread Error: "+ ex. Message +", "+ ex. StackTrace);
}
}
While (true)
{
If (ExecutedThreadCount==ThreadCount)
{
break;
}
}
}
//otherwise assigned by number of task
The else
{
for (int i=0; i {
Try
{
ParameterizedThreadStart PTS=new ParameterizedThreadStart (ExecuteInThread);
Thread th=new Thread (PTS);
List Param=new List (a);
Param=list. Skip (I), Take (1) ToList ();
Th. Start (param);
}
The catch (Exception ex)
{
The log. The Error (" Allot the Task by the Data Error: "+ ex. Message +", "+ ex. StackTrace);
}
}
While (true)
{
If (ExecutedThreadCount==list. Count)
{
break;
}
}
}
The Info (" ExecuteTask Ended at "+ DateTime. Now. The ToString (" MM - dd yyyy - HH: MM: ss") + ", Executed: "+ list. Count);
}
}
The catch (Exception ex)
{
The log. The Error (" EmailTask ExecuteTask: "+ ex. Message);
}
}
Private void ExecuteInThread (object param)
{
List List=param as List;
If (a list!=null)
{
The foreach (var item in the list)
{
ExecuteItem (item);
}
}
ExecutedThreadCount +=1;
}
//processing a single
Private void ExecuteItem (Model. Wf. EmailTask et)
{
WfBLL WWBLL=new WfBLL ();
Var task=WWBLL. GetMailTaskByID (et. ID);
Try
{
//handle special characters
Foreach (char rInvalidChar in Path. GetInvalidFileNameChars ())
{
Et. The Title=et. The Title. The Replace (rInvalidChar. The ToString (), string. The Empty);
}
Et. The Title=et. The Title. The Replace (" \ \ ", ""). The Replace ("/"," "). The Replace (" : ", ":"). The Replace (" ", "");
String filename=EmailConfig. PdfPath + et. The Title + "_" + et. ID + "PDF";
Bool flag=false,
HasFile=false;
If (string. IsNullOrEmpty (et. Attachment) | |! File. The Exists (et. Attachment))
{
Var st=GetPdf (et. ArticleID);
If (st!=null)
{
Using (FileStream fs=new FileStream (filename, FileMode. Create))
{
Fs. Write (st. ToArray (), 0, (int) st. Length);
Fs. Flush ();
Fs. The Close ();
}
Et. Attachment=filename;
Task. Attachment=filename;
HasFile=true;
}
}
The else
{
HasFile=true;
}
If (hasFile)
{
Flag=SendEmailHandler (et);
}
If (flag)
{
Task. The Result=1;
If (the File. The Exists (filename))
{File. Delete (filename); }
}
The else
{
Task. The Result=0;
}
}
The catch (Exception ex)
{
Task. The Result=0;
Log. The Error (" ExecuteTask Item: "+ et. ID +", Msg: "+ ex. Message);
}
The finally
{
Task. TryCount +=1;
WWBLL. The Update ();
}
}
//email
Public bool SendEmailHandler (Model. Wf. EmailTask et)
{
InterfaceLogBLL ibll=new InterfaceLogBLL ();
T_InterfaceLog l=new T_InterfaceLog ();
L.I nterfaceName="Send Email".
"Odule=" mail task assignment ";
L.P aram="to=" + et) MailTo + "& amp; Subject="+ et. Subject +" & amp; Atta="+ et. Attachment;
Try
{
L.C reateDate=DateTime. Now;
SendMail (et) MailTo, string. The Empty, et. The Subject, et. The Cnt, true, et. The Attachment).
Their lives esponseDate=DateTime. Now;
return true;
}
The catch (Exception ex)
{
Their lives emark=ex. The Message;
The log. The Error (" ExecuteTask SendEmail: "+ ex. Message +", MailTo: "+ et. MailTo);
return false;
}
The finally
{
Ibll. InsertLog (l);
}
}
///& lt; summary>
///email
///& lt;/summary>
///& lt; Param name="receivers" & gt; The recipient address, multiple use ";" Interval & lt;/param>
///& lt; Param name="cctos & gt;" Cc, multiple use ";" Interval & lt;/param>
///& lt; Param name="subject" & gt; Email title & lt;/param>
///& lt; Param name="CNT" & gt; Email body & lt;/param>
///& lt; Param name="isHtml & gt;" Whether the body HTML
///& lt; Param name="atta" & gt; The attachment address & lt;/param>
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related