public void Run() { SystemOptions so = new SystemOptions(ConnectionString); if ((ElectronTicket_Getway == "") || (ElectronTicket_Agent_UserNumber == "") || (ElectronTicket_Agent_Key == "") || (ElectronTicket_Agent_UserName == "") || (ElectronTicket_Agent_UserPassword == "") || (ElectronTicket_Agent_PostPassword == "")) { log.Write("ElectronTicket Task 参数配置不完整."); return; } // 已经启动 if (State == 1) { return; } lock (this) // 确保临界区被一个 Thread 所占用 { State = 1; gCount1 = 0; thread = new System.Threading.Thread(new System.Threading.ThreadStart(Do)); thread.IsBackground = true; thread.Start(); log.Write("ElectronTicket Task Start."); } }
protected override void OnStart(string[] args) { 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); } SystemOptions so = new SystemOptions(ConnectionString); // 上海大赢家电子票自动任务 try { if ((new DAL.Tables.T_Lotteries().GetCount(ConnectionString, "PrintOutType = 101") > 0)) { ElectronTicket_Task = new ElectronTicket(ConnectionString); ElectronTicket_Task.ElectronTicket_Getway = so["ElectronTicket_Getway"].ToString(""); ElectronTicket_Task.ElectronTicket_Agent_UserNumber = so["ElectronTicket_Agent_UserNumber"].ToString(""); ElectronTicket_Task.ElectronTicket_Agent_Key = so["ElectronTicket_Agent_Key"].ToString(""); ElectronTicket_Task.ElectronTicket_Agent_UserName = so["ElectronTicket_Agent_UserName"].ToString(""); ElectronTicket_Task.ElectronTicket_Agent_UserPassword = so["ElectronTicket_Agent_UserPassword"].ToString(""); ElectronTicket_Task.ElectronTicket_Agent_PostPassword = so["ElectronTicket_Agent_PostPassword"].ToString(""); Shove._IO.IniFile ini = new Shove._IO.IniFile(System.AppDomain.CurrentDomain.BaseDirectory + "Config.ini"); if ((ElectronTicket_Task.ElectronTicket_Getway != "") && (ElectronTicket_Task.ElectronTicket_Agent_UserNumber != "") && (ElectronTicket_Task.ElectronTicket_Agent_Key != "") && (ElectronTicket_Task.ElectronTicket_Agent_UserName != "") && (ElectronTicket_Task.ElectronTicket_Agent_UserPassword != "") && (ElectronTicket_Task.ElectronTicket_Agent_PostPassword != "")) { ElectronTicket_Task.Run(); } } } catch (Exception e) { new Log("System").Write("ElectronTicket 启动失败:" + e.Message); } // 上海大赢家自动录入开奖号任务 try { WinNumber_Task = new WinNumber(ConnectionString); WinNumber_Task.ElectronTicket_Getway = so["ElectronTicket_Getway"].ToString(""); WinNumber_Task.ElectronTicket_Agent_UserNumber = so["ElectronTicket_Agent_UserNumber"].ToString(""); WinNumber_Task.ElectronTicket_Agent_Key = so["ElectronTicket_Agent_Key"].ToString(""); WinNumber_Task.ElectronTicket_Agent_UserName = so["ElectronTicket_Agent_UserName"].ToString(""); WinNumber_Task.ElectronTicket_Agent_UserPassword = so["ElectronTicket_Agent_UserPassword"].ToString(""); WinNumber_Task.ElectronTicket_Agent_PostPassword = so["ElectronTicket_Agent_PostPassword"].ToString(""); Shove._IO.IniFile ini = new Shove._IO.IniFile(System.AppDomain.CurrentDomain.BaseDirectory + "Config.ini"); if ((WinNumber_Task.ElectronTicket_Getway != "") && (WinNumber_Task.ElectronTicket_Agent_UserNumber != "") && (WinNumber_Task.ElectronTicket_Agent_Key != "") && (WinNumber_Task.ElectronTicket_Agent_UserName != "") && (WinNumber_Task.ElectronTicket_Agent_UserPassword != "") && (WinNumber_Task.ElectronTicket_Agent_PostPassword != "")) { WinNumber_Task.Run(); } } catch (Exception e) { new Log("System").Write("WinNumber 启动失败:" + e.Message); } }