我如何...如何在Asp.Net中创建计数器? [英] How do I...How to create a counter in Asp.Net?

查看:89
本文介绍了我如何...如何在Asp.Net中创建计数器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Asp.Net创建计数器。



我应该如何创建一个柜台?



它应该像游戏中的计数器,你有4-5分钟需要完成任务,计数器按降序顺序移动,从4分钟开始,以00结束。

I want to create counter in Asp.Net.

How should I create a counter?

It should be like a counter in a game where you have 4-5 minutes and need to complete a task and the counter moves in a descending order that it starts from 4 minues and ends with 00.

推荐答案

您好darshantani,您可以按照这个教程 [ ^ ]。



可以找到另一篇好文章这里 [ ^ ]



希望它有所帮助。
Hi darshantani, you can follow this tutorial[^].

Another nice article can be found here[^]

Hope it helps.


使用ASP.NET定时器控件和Ajax创建倒计时器 [ ^ ]



Create Count Down Timer using ASP.NET Timer Control and Ajax[^]

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick">
        </asp:Timer>
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
    </ContentTemplate>
</asp:UpdatePanel>







protected void Page_Load(object sender, EventArgs e)
{
    if (Session["CountdownTimer"] == null)
    {
        Session["CountdownTimer"] = new CountDownTimer(TimeSpan.Parse("2:30:00"));
        (Session["CountdownTimer"] as CountDownTimer).Start();
    }
}
protected void Timer1_Tick(object sender, EventArgs e)
{
    if (Session["CountdownTimer"] != null)
    {
        Label1.Text = (Session["CountdownTimer"] as CountDownTimer).TimeLeft.ToString();
    }
}

public class CountDownTimer
{
    public TimeSpan TimeLeft;
    System.Threading.Thread thread;
    public CountDownTimer(TimeSpan original)
    {
        this.TimeLeft = original;
    }
    public void Start()
    {
        // Start a background thread to count down time
        thread = new System.Threading.Thread(() =>
        {
            while (true)
            {
                System.Threading.Thread.Sleep(1000);
                TimeLeft = TimeLeft.Subtract(TimeSpan.Parse("00:00:01"));
            }
        });
        thread.Start();
    }
}





代码从在其中 [ ^ ]。



-KR



Code is ripped from here[^].

-KR


这篇关于我如何...如何在Asp.Net中创建计数器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆