hai,
this is koti i was develop one windows service the mail concept behind is send a email at particular time instance i take one timer and write the code as follows
ADDSEmailServiceEvents("Service Started at ");---->method to write log file
TimerCallback timerDelegate = new TimerCallback(doWork);
// create timer and attach our method delegate to it
serviceTimer = new Timer(timerDelegate, null, 1000, 100);
suppose i am write the any message in the catch block or in the onStop EVENT then after when we start the service in windows i got one message box the is figured
bellow
attachments
public void doWork(object sender) {
try { Email emailObj = new Email(); string path;//= @"D:"; path = @"E:\EmailWindowsService\XmlDataFiles\";
DataSet dsEmailT = new DataSet(); DataSet dsSheDuleT = new DataSet(); DataSet dsSmtp = new DataSet(); DataSet dsUsers = new DataSet(); dsEmailT.ReadXml(path + "EmailTemplates.xml"); dsSheDuleT.ReadXml(path + "sheduleTemplate.xml"); dsSmtp.ReadXml(path + "SmtpSettings.xml"); int m = 0; foreach (DataRow dr in dsSheDuleT.Tables[0].Rows) {
#region SheduleForLoop
if (dr["EmailTemplateName"].ToString() == null || dr["EmailTemplateName"].ToString().Trim() == "0" || dr["EmailTemplateName"].ToString().Trim() == "") m++; else {
if (((Convert.ToDateTime(DateTime.Now.ToString())).CompareTo(Convert.ToDateTime(dr["SheduleTime"].ToString())) != -1)) { if (dr["Status"].ToString() != "Send" || dr["Status"].ToString().Contains("pending")) { DataRow[] emailT = dsEmailT.Tables[0].Select("id=" + dr["EmailTemplateName"].ToString().Trim()); emailObj.UserName = emailT[0]["UserName"].ToString(); emailObj.Password = emailT[0]["Password"].ToString(); emailObj.Port = Convert.ToInt32(dsSmtp.Tables[0].Rows[0]["PortNo"]); emailObj.HostName = dsSmtp.Tables[0].Rows[0]["Host"].ToString(); emailObj.FromAddress = emailT[0]["FromAddress"].ToString(); emailObj.Subject = emailT[0]["Subject"].ToString(); emailObj.Body = emailT[0]["Body"].ToString(); dsUsers.ReadXml(path + "users.xml"); #region userForLoop int i = 0; foreach (DataRow user in dsUsers.Tables[0].Rows) { i++; dsUsers.WriteXml("E:\\userS.xml"); if (user["UserId"].ToString() == null || user["UserId"].ToString().Trim() == "0" || user["UserId"].ToString() == "") i++; else {
if (Convert.ToBoolean(user["isActive"])) emailObj.ToAddresses.Add(new MailAddress(user["EmailId"].ToString())); }
} #endregion emailObj.sendEmail(true); dr["Status"] = "Send"; //ADDSEmailServiceEvents("mail Send "); } } }
dsSheDuleT.WriteXml(path + "sheduleTemplate.xml"); } #endregion
} catch (Exception ex) { //string local_strMsg = "Problem in service at starting stage"; //ADDSEmailServiceEvents("exception: " + ex.Message); } }
|
what is the problem with my webservice