我的C#计时器不起作用 [英] My C# Timer Does Not Work
本文介绍了我的C#计时器不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的应用程序中使用计时器更新进度条.我有一个按钮可以启动计时器.
I am using a timer in my application to update progressbar. I have a button to start the timer.
private void btnLogin_Click(object sender, EventArgs e)
{
timer1.Start();
}
我将计时器间隔设置为1000.因此,它应该在每1000毫秒后滴答一次.每当计时器计时时,我都会执行一些代码.但是问题是,即使单击按钮,计时器也不会滴答.
据我所知,如果我启动计时器,那么它应该在间隔之后调用timer.Tick().
I have timer interval set to 1000. So, it should tick after every 1000 msec. I have some code to be executed each time the timer ticks. But the problem is, timer never ticks even after clicking the button.
As far as I know, if I start the timer, then it should call the timer.Tick() after the interval.
推荐答案
如果您使用的是-''System.Timers.Timer
'',确保将计时器的Enabled
属性设置为true
.
If you are using - ''System.Timers.Timer
'', make sure the Timer''sEnabled
property is set totrue
.
如何设置 ^ ],它应类似于:
How did you set-up the timer[^], it should look like:
// Create a timer with a ten second interval.
aTimer = new System.Timers.Timer(10000);
// Hook up the Elapsed event for the timer.
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
计时器函数应如下所示:
and the timer function should look like:
// Specify what you want to happen when the Elapsed event is
// raised.
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
}
我认为这将解决您的问题:-
Jst Read This What r go here .....
I think this will solve ur Problem :-
Jst Read This what r going here .....
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Import Namespace="System.Collections.Generic" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
List<string> Quote = new List<string>();
Quote.Add("A");
Quote.Add("B");
Quote.Add("C");
Random rnd = new Random();
lblQuote.Text = Quote[rnd.Next(Quote.Count)];
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Timer Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"/>
<asp:Timer ID="Timer1" Interval="2000" runat="server"/>
<fieldset>
<legend>Quotes</legend>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</triggers>
<contenttemplate>
<asp:Label ID="lblQuote" runat="server" />
</contenttemplate>
</fieldset>
</div>
</form>
</body>
</html></string></string>
这篇关于我的C#计时器不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文