mySmsService 是windows的一個主服務, startSend是一個類,在同一個命名空間下面。
ifHaveSend()是startSend的一個public方法 private void sendBookingSMS() 也是startSend的一個private 方法。mySmsService 的定時事件。
private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
function fun = new function();
fun.ErrorMsg("開始");
this.timer1.Enabled = false;
startSend ssend = new startSend();
ssend.ifHaveSend();
this.timer1.Enabled = true;
}當調用ssend.ifHaveSend();
當條件成立的時候 在ifHaveSend()方法中調用 本類的private方法 sendBookingSMS 。
剛開始部署。的時候本服務一直沒有按照預期的執行。無奈用try catch追蹤到當ifHaveSend條件成立調用本類的方法sendBookingSMS 的時候。並把錯誤日志寫入到txt文件中。發現錯誤信息。大體如下“未將對象的應用綁定到對象的執行個體。”這個錯誤讓我百思不得其解,如果誰有這方面的經驗請告訴我。追蹤代碼如下try
{
sendBookingSMS();
}
catch(Exception ex)
{
fun.ErrorMsg(ex.ToString());
}
ifHaveSend()是startSend的一個public方法 private void sendBookingSMS() 也是startSend的一個private 方法。mySmsService 的定時事件。
private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
function fun = new function();
fun.ErrorMsg("開始");
this.timer1.Enabled = false;
startSend ssend = new startSend();
ssend.ifHaveSend();
this.timer1.Enabled = true;
}當調用ssend.ifHaveSend();
當條件成立的時候 在ifHaveSend()方法中調用 本類的private方法 sendBookingSMS 。
剛開始部署。的時候本服務一直沒有按照預期的執行。無奈用try catch追蹤到當ifHaveSend條件成立調用本類的方法sendBookingSMS 的時候。並把錯誤日志寫入到txt文件中。發現錯誤信息。大體如下“未將對象的應用綁定到對象的執行個體。”這個錯誤讓我百思不得其解,如果誰有這方面的經驗請告訴我。追蹤代碼如下try
{
sendBookingSMS();
}
catch(Exception ex)
{
fun.ErrorMsg(ex.ToString());
}
解决方案 »
- 讨论有关将.net 中文版网站换成英文版网站的方案?
- 用户登录浏览器关闭自动注销
- 大家看一下,这个效果是怎么实现的
- 连接数据库的问题。。。。。。。。。。。
- 急...HTML页面WindowsMediaPlayer控件超链接的问题
- SQL Server 数据中改变数据库表名和改变列名的SQL数据是什么?
- js问题?
- 使用IE的打印控件怎么设定打印页面的默认大小?
- 怎么解决
- 是不是都在吃饭拉?急求一个正则表达式!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 请教关于在DataGrid模板列中绑定单选按钮的问题?谢谢
- DataGrid超链列能否显示的内容为实际超链地址的一部分?
用的是System.Timers.Timer
如果正确。
确定windows service下与winform程序的环境是否一致,例如配置文件,执行程序权限等
this.timer1.Enabled = true; 改为 this.timer1.interval=60000;
试试看呢,以前碰到过不能用enable属性的情况
this.timer1.Enabled = true; 改为 this.timer1.interval=60000;
试试看呢,以前碰到过不能用enable属性的情况
也可以enable
只不过要用两个timer
用線程也會出項這個問題。
//時間:2006/7/21 下午 02:03:50
//描述:
System.NullReferenceException: 並未將物件參考設定為物件的執行個體
at SmsWindowsService.startSend.sendBookingSMS(String shopid, String cardno, String Totel1, String Totel2, String smscase, String BookSendDate, String BookSendTime, String SendRule, String SendPar, String LastSendDate, String ID, String BookMan, String BookDate, String BookTime, String smsty)
at SmsWindowsService.startSend.ifHaveSend()
//-----------------------------------------------------------------------------------------------------------
#region/// 是檢查是否有需要發送的息 如果有則開始傳送簡訊
public void ifHaveSend()
{
string shopid="",cardno="",Totel1="",Totel2="",smscase="",BookSendDate="",BookSendTime="",SendRule="",SendPar="",LastSendDate="",ID="",BookMan="",BookDate="",BookTime="",smsty="";
function fun = new function("conStr");
//將需要傳送信息的數據取出放入表中
string sqlStr = "SELECT shopid,cardno,Totel1,Totel2,smscase,BookSendDate,BookSendTime,SendRule,SendPar,LastSendDate,ID,BookMan,BookDate,BookTime,smsty FROM SendInfo";
DataTable myTb = new DataTable(); fun = new function("conStr");
fun.ReDataTable(ref myTb,sqlStr,"");
int n = myTb.Rows.Count; #region
for(int i=0;i<n;i++)
{
shopid=myTb.Rows[i][0].ToString().Trim();
cardno=myTb.Rows[i][1].ToString().Trim();
Totel1=myTb.Rows[i][2].ToString().Trim();
Totel2=myTb.Rows[i][3].ToString().Trim();
smscase=myTb.Rows[i][4].ToString().Trim();
BookSendDate=myTb.Rows[i][5].ToString().Trim();
BookSendTime=myTb.Rows[i][6].ToString().Trim();
SendRule=myTb.Rows[i][7].ToString().Trim();
SendPar=myTb.Rows[i][8].ToString().Trim(); if(myTb.Rows[i][9].ToString().Trim() != "")
LastSendDate = myTb.Rows[i][9].ToString().Trim();
else
LastSendDate = "1900/01/01"; ID = myTb.Rows[i][10].ToString().Trim();
BookMan = myTb.Rows[i][11].ToString().Trim();
if(myTb.Rows[i][12].ToString().Trim() != "")
BookDate = Convert.ToDateTime(myTb.Rows[i][12]).ToString("yyyy/MM/dd");
else
BookDate = "1900/01/01"; if(myTb.Rows[i][13].ToString().Trim() != "")
BookTime = Convert.ToDateTime(myTb.Rows[i][13]).ToString("HH:mm:ss");
else
BookTime = "00:00:00";
smsty = myTb.Rows[i][14].ToString();
try
{
sendBookingSMS(shopid,cardno,Totel1,Totel2,smscase,BookSendDate,BookSendTime,SendRule,SendPar,LastSendDate,ID,BookMan,BookDate,BookTime,smsty);
}
catch(Exception ex)
{
fun.ErrorMsg(ex.ToString());
}
}
#endregion }
#endregion