这个程序有什么地方出错吗???(timer不起作用)

jacky125 2006-05-26 11:27:40
大家帮忙看看,为什么我的程序只能运行一次,timer不起作用
------------------------------------------------------------------------
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.timer1 = new System.Windows.Forms.Timer(this.components);
//
// timer1
//
this.timer1.Interval = 1000;
this.timer1.Enabled = true;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);


}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}



private void timer1_Tick(object sender, System.EventArgs e)
{

string connection = ConfigurationSettings.AppSettings["GetConncetion"].ToString();
string extno1 = ConfigurationSettings.AppSettings["extno1"].ToString();
string uid = ConfigurationSettings.AppSettings["uid"].ToString();
string pswd = ConfigurationSettings.AppSettings["pswd"].ToString();
SqlConnection myconnection = new SqlConnection(connection);
myconnection.Open();
string selectstring = "select top 2 * from TSMS where MobileNum between '130' and '133' order by MobileID";
SqlDataAdapter mycommand = new SqlDataAdapter(selectstring, myconnection);
DataTable dt = new DataTable();
mycommand.Fill(dt);
HttpWebResponse res = null;
for(int i=0;i<dt.Rows.Count;i++)
{

string strmsg = System.Web.HttpUtility.UrlEncode((string)dt.Rows[i]["Content"],System.Text.Encoding.GetEncoding("GB2312"));
string strmob = (string)dt.Rows[i]["MobileNum"];
string strUrl = "http://econnect.hotdotchina.com/econnect/pitf/submit.jsp?uid=" + uid + "&pswd=" + pswd + "&extno=" + extno1 + "&msg=" + strmsg + "&mob=" + strmob;
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(strUrl);
res = (HttpWebResponse)req.GetResponse ();

}




}
...全文
277 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
jacky125 2006-06-02
  • 打赏
  • 举报
回复
copico(一路向北)
-------------------------------------------------------------
我的数据库里面的数据会不断变化的,这样好象不行呀
jacky125 2006-06-01
  • 打赏
  • 举报
回复
copico(一路向北)
-------------------------------------------------------------
我的数据库里面的数据会不断变化的,这样好象不行呀
jacky125 2006-06-01
  • 打赏
  • 举报
回复
大家帮忙看看
copico 2006-05-31
  • 打赏
  • 举报
回复
Re:http://community.csdn.net/Expert/topic/4780/4780398.xml?temp=.5009424
----------------------------....

threading.thread t = new threading.thread(run)
t.start() '线程
===================
private void run()
{
string connection = ConfigurationSettings.AppSettings["GetConncetion"].ToString();
string extno1 = ConfigurationSettings.AppSettings["extno1"].ToString();
string uid = ConfigurationSettings.AppSettings["uid"].ToString();
string pswd = ConfigurationSettings.AppSettings["pswd"].ToString();
SqlConnection myconnection = new SqlConnection(connection);
myconnection.Open();
string selectstring = "select top 2 * from TSMS where MobileNum between '130' and '133' order by MobileID";
SqlDataAdapter mycommand = new SqlDataAdapter(selectstring, myconnection);
DataTable dt = new DataTable();
mycommand.Fill(dt);
HttpWebResponse res = null;
for(int i=0;i<dt.Rows.Count;i++)
{

string strmsg = System.Web.HttpUtility.UrlEncode((string)dt.Rows[i]["Content"],System.Text.Encoding.GetEncoding("GB2312"));
string strmob = (string)dt.Rows[i]["MobileNum"];
string strUrl = "http://econnect.hotdotchina.com/econnect/pitf/submit.jsp?uid=" + uid + "&pswd=" + pswd + "&extno=" + extno1 + "&msg=" + strmsg + "&mob=" + strmob;
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(strUrl);
res = (HttpWebResponse)req.GetResponse ();

}
}
jacky125 2006-05-29
  • 打赏
  • 举报
回复
大家帮忙看看,有没有代码呀
jacky125 2006-05-26
  • 打赏
  • 举报
回复
为什么要把读数据库的放在timer里,放在一个线程里也比timer里好
--------------------------------------------------------------------------
怎么放在一个线程里呀???有代码吗????
Firestone2003 2006-05-26
  • 打赏
  • 举报
回复
start呢?
copico 2006-05-26
  • 打赏
  • 举报
回复
为什么要把读数据库的放在timer里,放在一个线程里也比timer里好
diandian82 2006-05-26
  • 打赏
  • 举报
回复
mark
chengpei_chen 2006-05-26
  • 打赏
  • 举报
回复

this.timer1.Interval = 1000;
this.timer1.Enabled = true;
me.Timer1.Start();
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
这样试试
jacky125 2006-05-26
  • 打赏
  • 举报
回复
大家帮忙看看,有没有代码呀
jacky125 2006-05-26
  • 打赏
  • 举报
回复
大家帮忙看看,有没有代码呀
wlei9802 2006-05-26
  • 打赏
  • 举报
回复
给你一个使用线程的例子
http://www.chinaworkroom.com/Bbs/ViewTopic.aspx?TopicID=193&boardID=8
jacky125 2006-05-26
  • 打赏
  • 举报
回复
不会用线程,大家帮忙看看,有没有代码呀
pangjiang 2006-05-26
  • 打赏
  • 举报
回复
还有就是在timer,控件时间里不要循环访问数据库,那样会使你的程序在timer控件时间被触发的时候变的很慢,要是你机器性能不好点,程序就死了
在里面用线程,更合理一点,以上是我的两点意见!望大家指教
pangjiang 2006-05-26
  • 打赏
  • 举报
回复
你把time的enable先设置为false
然后在你的load里把它置为ture
就可以了
liujiwe79 2006-05-26
  • 打赏
  • 举报
回复
如果你的数据是不段增加的,建议你在数据库层建一个触发器就可以了,没有必要放在timer里,影响效率
copico 2006-05-26
  • 打赏
  • 举报
回复
不是触发去运行么?
jacky125 2006-05-26
  • 打赏
  • 举报
回复
我的数据是不断增加的,所以需要定时的运行程序
copico 2006-05-26
  • 打赏
  • 举报
回复
我的意思是,你别用timer1啊
你直接把timer1里的代码拷出来,直接运行不行么?

因为timer1有个周期,在这个周期内不管你数据处理完没有,都是要结束的,很容易引发异常

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧