小编Man*_*čić的帖子

DateTime类作为秒表

我的学校项目是用一个按钮启动/停止来开始计算时间,然后再点击停止计算时间.当我使用这3行

txtVrijeme.Text = Convert.ToString(sada.AddSeconds(i).ToString("HH:mm:ss"));
Thread.Sleep(1000);
i++;
Run Code Online (Sandbox Code Playgroud)

在形式apk中没有循环(while,for,goto等).它工作(显示00:00:00,如果我再次点击00:00:01)但是当我使用循环它不显示任何东西.为什么?顺便说一句.控制台应用程序使用此代码没有任何问题(在控制台中循环)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Bradi?i?ManuelŠtoperica
{
    public partial class Form1 : Form
    {
        DateTime sada = new DateTime(2009, 6, 22, 0, 0, 0);
        int i = 0;
        bool x = true;

        public Form1()
        {
            InitializeComponent();                
        }

        void execute(bool y)
        {

            while (y == true)
             {
                txtVrijeme.Text = Convert.ToString(sada.AddSeconds(i).ToString("HH:mm:ss"));
                Thread.Sleep(1000);
                i++;
            }
        }


        private void btnStartStop_Click(object sender, …
Run Code Online (Sandbox Code Playgroud)

c# datetime

-1
推荐指数
1
解决办法
70
查看次数

标签 统计

c# ×1

datetime ×1