开发者

Count down timer in WP7

I want a count down timer to start ticking for two and half hours . I tried this using dispatcher timer

Please find the code below. But it is not updating the seconds properly. It is too fast. It ticks two seconds instead of 1 second at a time

    private void DrawBlackout()
    {
        TextBlock videoText = new TextBlock();
        dt = new DispatcherTimer();
        dt.Interval = new TimeSpan(0,0,1); // 1 Seconds
        dt.Tick += new EventHandler(dt_Tick);
        dt.Start();


    }

    void dt_Tick(object sender, EventArgs e)
    {
        // do something

       milliseconds = milliseconds - 1000;
       label.Text = getTimeText(milliseconds / 1000);
       elapsed += 1000;

        //Debug.WriteLine(stopwatch.ElapsedMilliseconds + "\n");
        if (milliseconds <= 1000)
            dt.Stop();
     }



    String getTimeText(long secVal)
    {

        String timeString 开发者_C百科= "";
        int seconds = (int)(secVal % 60);
        int minutes = (int)((secVal / 60) % 60);
        int hours = (int)((secVal / (60 * 60)) % 60);
        if (hours <= 9)
            timeString = "0" + Convert.ToString(hours) + " : ";
        else
            timeString = Convert.ToString(hours) + " : ";
        if (minutes <= 9)
            timeString = timeString + "0" + Convert.ToString(minutes) + " : ";
        else
            timeString = timeString + Convert.ToString(minutes) + " : ";
        if (seconds <= 9)
            timeString = timeString + "0" + Convert.ToString(seconds) + " ";
        else
            timeString = timeString + Convert.ToString(seconds) + " ";
        return timeString;
    }

Please help to resolve this issue.


void DisTimer_Tick(object sender, EventArgs e)
        {
            timeRefresh++;
            if (sec > 0)
            {
                sec--;
            }
            else if (sec == 0 && min > 0)
            {
                sec = 59;
                min--;
            }
            else if (sec == 0 && min == 0 && house > 0)
            {
                sec = 59;
                min = 59;
                house--;
            }
            txtHouse.Text = house.ToString();
            txtMin.Text = min.ToString();
            txtSec.Text = sec.ToString();

            if (sec == 0 && min == 0 && house == 0)
            {
                DisTimer.Tick -= new EventHandler(DisTimer_Tick);
                getBuyer();
            }
            else if (timeRefresh == 60)
            {
                getBuyer();
                DisTimer.Tick -= new EventHandler(DisTimer_Tick);
            }
        }

I hope to help you!

Thongaduka ( diadiem JSC)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜