public void Run() { // 已经启动 if (State == 1) { return; } SystemOptions so = new SystemOptions(ConnectionString); Betting_SMS_UserID = so["Betting_SMS_UserID"].Value.ToString(); Betting_SMS_UserPassword = so["Betting_SMS_UserPassword"].Value.ToString(); Betting_SMS_RegCode = so["Betting_SMS_RegCode"].Value.ToString(); if ((Betting_SMS_UserID == "") || (Betting_SMS_UserPassword == "")) { State = 0; msg.Send("SmsBetting: SMS config error."); log.Write("SmsBetting: SMS config error."); return; } segg = new SMS.Eucp.Gateway.Gateway(Betting_SMS_UserID, Betting_SMS_UserPassword); if (segg == null) { State = 0; msg.Send("SmsBetting: SMS Gateway open error."); log.Write("SmsBetting: SMS Gateway open error."); return; } if (Betting_SMS_RegCode != "") { segg.SetKey(Betting_SMS_RegCode); } lock (this) // 确保临界区被一个 Thread 所占用 { State = 1; gCount1 = 0; thread = new System.Threading.Thread(new System.Threading.ThreadStart(Do)); thread.IsBackground = true; thread.Start(); msg.Send("SmsBettingTask Start."); log.Write("SmsBettingTask Start."); } }
public void Run() { // 已经启动 if (State == 1) { return; } SystemOptions so = new SystemOptions(ConnectionString); Betting_SMS_UserID = so["Betting_SMS_UserID"].Value.ToString(); Betting_SMS_UserPassword = so["Betting_SMS_UserPassword"].Value.ToString(); Betting_SMS_RegCode = so["Betting_SMS_RegCode"].Value.ToString(); if ((Betting_SMS_UserID == "") || (Betting_SMS_UserPassword == "")) { State = 0; msg.Send("SendSMSTask: SMS config error."); log.Write("SendSMSTask: SMS config error."); return; } segg = new SMS.Eucp.Gateway.Gateway(Betting_SMS_UserID, Betting_SMS_UserPassword); if (segg == null) { State = 0; msg.Send("SendSMSTask: SMS Gateway open error."); log.Write("SendSMSTask: SMS Gateway open error."); return; } if (Betting_SMS_RegCode != "") { segg.SetKey(Betting_SMS_RegCode); } lock (this) // 确保临界区被一个 Thread 所占用 { State = 1; gCount1 = 0; thread = new System.Threading.Thread(new System.Threading.ThreadStart(Do)); thread.IsBackground = true; thread.Start(); msg.Send("SendSMSTask Start."); log.Write("SendSMSTask Start."); } }
private int Send() { DAL.Tables.T_SMS sms = new DAL.Tables.T_SMS(); DataTable dt = sms.Open(ConnectionString, " top 100 [ID], [To], [DateTime], [Content]", "IsSent = 0", "[DateTime]"); if (dt == null) { log.Write("Send is Fail: Data read fail."); return(-1); } if (dt.Rows.Count == 0) { return(0); } int Count = 0; segg = new SMS.Eucp.Gateway.Gateway(Betting_SMS_UserID, Betting_SMS_UserPassword); if (segg == null) { State = 0; msg.Send("SendSMSTask: SMS Gateway open error."); log.Write("SendSMSTask: SMS Gateway open error."); return(-1); } foreach (DataRow dr in dt.Rows) { SMS.Eucp.Gateway.CallResult Result = segg.Send(dr["To"].ToString(), dr["Content"].ToString()); if (Result.Code < 0) { log.Write("Send is Fail: " + Result.Description); } else { Count++; } sms.IsSent.Value = true; sms.Update(ConnectionString, "[ID] = " + dr["ID"].ToString()); System.Threading.Thread.Sleep(500); } return(Count); }
private int Send() { DAL.Tables.T_SMS sms = new DAL.Tables.T_SMS(); DataTable dt = sms.Open(ConnectionString, " top 100 [ID], [To], [DateTime], [Content]", "IsSent = 0", "[DateTime]"); if (dt == null) { log.Write("Send is Fail: Data read fail."); return -1; } if (dt.Rows.Count == 0) { return 0; } int Count = 0; segg = new SMS.Eucp.Gateway.Gateway(Betting_SMS_UserID, Betting_SMS_UserPassword); if (segg == null) { State = 0; msg.Send("SendSMSTask: SMS Gateway open error."); log.Write("SendSMSTask: SMS Gateway open error."); return -1; } foreach (DataRow dr in dt.Rows) { SMS.Eucp.Gateway.CallResult Result = segg.Send(dr["To"].ToString(), dr["Content"].ToString()); if (Result.Code < 0) { log.Write("Send is Fail: " + Result.Description); } else { Count++; } sms.IsSent.Value = true; sms.Update(ConnectionString, "[ID] = " + dr["ID"].ToString()); System.Threading.Thread.Sleep(500); } return Count; }