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."); } }
protected override void OnStart(string[] args) { SystemOptions so = new SystemOptions(ConnectionString); #region 自动连接数据库 try { System.Data.SqlClient.SqlConnection conn = Shove.Database.MSSQL.CreateDataConnection <System.Data.SqlClient.SqlConnection>(ConnectionString); while (conn.State != ConnectionState.Open) { conn.Open(); new Log("System").Write("数据库连接失败"); System.Threading.Thread.Sleep(1000); } conn.Close(); } catch (Exception e) { new Log("System").Write(e.Message); } #endregion #region 自动任务 try { task = new Task(ConnectionString); task.Run(); } catch (Exception e) { new Log("System").Write("Task 启动失败:" + e.Message); } #endregion #region 自动任务发送短信 try { SendSms_Task = new SendSMSTask(ConnectionString); SendSms_Task.Run(); } catch (Exception e) { new Log("System").Write("SendSMSTask 启动失败:" + e.Message); } #endregion #region 自动任务短信接收 try { if (so["Betting_SMS_Status_ON"].ToBoolean(false)) { SmsBetting_Task = new SmsBettingTask(ConnectionString); SmsBetting_Task.Run(); } } catch (Exception e) { new Log("System").Write("SmsBettingTask 启动失败:" + e.Message); } #endregion }