c# 为什么Timer的代码只执行一次?
protectedvoidTimer1_Tick(objectsender,EventArgse){Textbox1.Text=Textbox1.Text+Textbox...
protected void Timer1_Tick(object sender, EventArgs e)
{
Textbox1.Text = Textbox1.Text + Textbox1.Text;
}
textbox1相加代码执行之后,timer控件就不再执行上面的代码了,但timer控件还是在运行,就是不执行,为什么会这样的呢?
protected void Page_Load(object sender, EventArgs e)
{
Textbox1.Text = "ABC";
}
timer执行了一次代码
也就是Textbox1.text="ABCABC"之后就不再执行控件里面的代码了
但timer是在运行的,Textbox1.text就一直等于“ABCABC”了
我就是用AJAX的timer控件,UpDatepanel都设置完成了 展开
{
Textbox1.Text = Textbox1.Text + Textbox1.Text;
}
textbox1相加代码执行之后,timer控件就不再执行上面的代码了,但timer控件还是在运行,就是不执行,为什么会这样的呢?
protected void Page_Load(object sender, EventArgs e)
{
Textbox1.Text = "ABC";
}
timer执行了一次代码
也就是Textbox1.text="ABCABC"之后就不再执行控件里面的代码了
但timer是在运行的,Textbox1.text就一直等于“ABCABC”了
我就是用AJAX的timer控件,UpDatepanel都设置完成了 展开
展开全部
你这样写会出问题的,string类型相加下去会很长,可能 已经超出那个控件的容量 了!!建议给个判断下Timer停下来!
private void timer1_Tick(object sender, EventArgs e)
{
text1.Text = text1.Text + text1.Text;
if (text1.Text.Length > 100000)
{
timer1.Enabled = false;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
text1.Text = text1.Text + text1.Text;
if (text1.Text.Length > 100000)
{
timer1.Enabled = false;
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
定时器设置的enabled=true,interval=1000,运行程序时,代码只执行成一次:
//定时器每秒执行一次
private
void
timer1_Tick(object
sender,
EventArgs
e)
{
thread1=
new
Thread(new
ThreadStart(zairuthread));
thread1.IsBackground
=
true;
thread1.Start();
}
private
void
zairuthread()
{
if
(this.InvokeRequired)
{
this.BeginInvoke(new
EventHandler(zairu),
null);
}
else
{
zairu(this,
null);
}
}
private
void
zairu(object
sender,
EventArgs
e)
{
mvideo.GrabImage("D:\\1.jpg");//**
List
list
=
new
List
();
list
=
FaceFind.FaceShowzhuye(pictureBox_get.Width,
pictureBox_get.Height,
"D:\\1.jpg");
int
i
=
list.Count;
switch
(i)
{
case
1:
pictureBox_get.Image
=
list[0];
}
thread1.Abort();
thread1.Join();
}
//定时器每秒执行一次
private
void
timer1_Tick(object
sender,
EventArgs
e)
{
thread1=
new
Thread(new
ThreadStart(zairuthread));
thread1.IsBackground
=
true;
thread1.Start();
}
private
void
zairuthread()
{
if
(this.InvokeRequired)
{
this.BeginInvoke(new
EventHandler(zairu),
null);
}
else
{
zairu(this,
null);
}
}
private
void
zairu(object
sender,
EventArgs
e)
{
mvideo.GrabImage("D:\\1.jpg");//**
List
list
=
new
List
();
list
=
FaceFind.FaceShowzhuye(pictureBox_get.Width,
pictureBox_get.Height,
"D:\\1.jpg");
int
i
=
list.Count;
switch
(i)
{
case
1:
pictureBox_get.Image
=
list[0];
}
thread1.Abort();
thread1.Join();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
定时器设置的enabled=true,interval=1000,运行程序时,代码只执行成一次:
//定时器每秒执行一次
private void timer1_Tick(object sender, EventArgs e)
{
thread1= new Thread(new ThreadStart(zairuthread));
thread1.IsBackground = true;
thread1.Start();
}
private void zairuthread()
{
if (this.InvokeRequired)
{
this.BeginInvoke(new EventHandler(zairu), null);
}
else
{
zairu(this, null);
}
}
private void zairu(object sender, EventArgs e)
{
mvideo.GrabImage("D:\\1.jpg");//**
List<Image> list = new List<Image>();
list = FaceFind.FaceShowzhuye(pictureBox_get.Width, pictureBox_get.Height, "D:\\1.jpg");
int i = list.Count;
switch (i)
{
case 1:
pictureBox_get.Image = list[0];
}
thread1.Abort();
thread1.Join();
}
//定时器每秒执行一次
private void timer1_Tick(object sender, EventArgs e)
{
thread1= new Thread(new ThreadStart(zairuthread));
thread1.IsBackground = true;
thread1.Start();
}
private void zairuthread()
{
if (this.InvokeRequired)
{
this.BeginInvoke(new EventHandler(zairu), null);
}
else
{
zairu(this, null);
}
}
private void zairu(object sender, EventArgs e)
{
mvideo.GrabImage("D:\\1.jpg");//**
List<Image> list = new List<Image>();
list = FaceFind.FaceShowzhuye(pictureBox_get.Width, pictureBox_get.Height, "D:\\1.jpg");
int i = list.Count;
switch (i)
{
case 1:
pictureBox_get.Image = list[0];
}
thread1.Abort();
thread1.Join();
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
protected void Page_Load(object sender, EventArgs e)
{
Textbox1.Text = "ABC";
}
//在上面这个窗体加载事件里,你在补充一下:
protected void Page_Load(object sender, EventArgs e)
{
Timer1.Start(); //开启计时功能
Textbox1.Text = "ABC";
}
{
Textbox1.Text = "ABC";
}
//在上面这个窗体加载事件里,你在补充一下:
protected void Page_Load(object sender, EventArgs e)
{
Timer1.Start(); //开启计时功能
Textbox1.Text = "ABC";
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
ASP.NET用不了TIMER,除非用AJAX
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询